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

  • Thread starter Thread starter charan1
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion revolves around solving the distance to the horizon formula for Earth and Mars using MATLAB. The formula is d=sqrt(2rh+h^2), where d is the distance, r is the radius, and h is the height. The user encounters errors related to syntax in their MATLAB code, specifically with unbalanced parentheses and incorrect use of the period operator. Clarification is provided that the period is part of the operator for element-wise operations, not the variable itself. The conversation emphasizes the importance of correct syntax and understanding MATLAB's element-wise operations for successful implementation.
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...
 
The problem is that you have an extra period in this line
charan1 said:
>> d=sqrt((2*r.*h.)+(h.^2))
 
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.
 
Oh I see Thank you!
 
Back
Top