Homework Help: Matlab Help Needed Meshgrid

1. Dec 1, 2009

charan1

1. The problem statement, all variables and given/known data

The distance to the horizon increases as you climb a mountain:
d=sqrt(2rh+h^2)

d=distance to the horizon
h=height of hill

solve for Earth's and Mar's radius

for heights from 0ft-10,000ft

3. The attempt at a solution

This is what I did but I keep getting an error

>> R=[20924640, 11132880]

R =

20924640 11132880

>> H=0:1:10000

>> [r,h]=meshgrid(R,H)

>> d=sqrt((2*r.*h.)+(h.^2))
??? d=sqrt((2*r.*h.)+(h.^2))
|
Error: Unbalanced or unexpected parenthesis or bracket.

>> d=sqrt(2*r.*h.+h.^2)
??? d=sqrt(2*r.*h.+h.^2)
|
Error: Unexpected MATLAB operator.

2. Dec 1, 2009

charan1

also the problem says I have to use meshgrid...I know there's a way to do this without doing that...

3. Dec 1, 2009

Staff: Mentor

The problem is that you have an extra period in this line

4. Dec 1, 2009

charan1

But I thought you have to put a period after each vector variable?

5. Dec 1, 2009

Staff: Mentor

No, you misunderstand. The period is part of the operator, not part of the variable, and means that the operation is to be applied to each element of the vector.

6. Dec 2, 2009

charan1

Oh I see Thank you!