Solve for Earth and Mars Radius: Distance to the Horizon Formula

  • Thread starter Thread starter charan1
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
5 replies · 8K views
charan1
Messages
40
Reaction score
0

Homework Statement



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

d=distance to the horizon
r=radius's
h=height of hill

solve for Earth's and Mar's radius
Earths radius Feet: 20924640
Mars radius feet: 11132880

for heights from 0ft-10,000ft

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.

I'm not exactly sure what the problem is, please help!
 
Physics news on Phys.org
also the problem says I have to use meshgrid...I know there's a way to do this without doing that...
 
But I thought you have to put a period after each vector variable?
 
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.