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

  • Thread starter Thread starter charan1
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary

Discussion Overview

The discussion revolves around solving for the radii of Earth and Mars using the distance to the horizon formula, specifically addressing a homework problem that involves calculations for heights ranging from 0 to 10,000 feet.

Discussion Character

  • Homework-related

Main Points Raised

  • One participant presents a formula for calculating the distance to the horizon and attempts to implement it in MATLAB, specifying the radii of Earth and Mars.
  • The participant encounters errors in their MATLAB code and seeks assistance in resolving these issues.
  • Another participant identifies a specific error related to an extra period in the code, suggesting it is causing the problem.
  • A clarification is provided regarding the use of the period in MATLAB, indicating that it is part of the operator for element-wise operations, not the variable itself.
  • The original poster expresses understanding after the clarification about the operator usage.

Areas of Agreement / Disagreement

Participants generally agree on the nature of the errors in the MATLAB code, but there is a brief misunderstanding regarding the use of the period in vector operations that is clarified during the discussion.

Contextual Notes

Limitations: The discussion does not resolve the broader implications of the distance to the horizon formula or its application beyond the specific homework context.

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!
 

Similar threads

  • · Replies 23 ·
Replies
23
Views
4K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K