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

  • Thread starter charan1
  • Start date
  • Tags
    Matlab
In summary, the conversation discussed how the distance to the horizon increases as you climb a mountain, and provided the formula d=sqrt(2rh+h^2) to calculate it. It also asked to solve for the Earth's and Mars's radius in feet and for heights from 0ft-10,000ft using meshgrid. However, the attempt at a solution resulted in errors due to an extra period in the code.
  • #1
charan1
41
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
  • #2
also the problem says I have to use meshgrid...I know there's a way to do this without doing that...
 
  • #3
The problem is that you have an extra period in this line
charan1 said:
>> d=sqrt((2*r.*h.)+(h.^2))
 
  • #4
But I thought you have to put a period after each vector variable?
 
  • #5
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
Oh I see Thank you!
 

1. What is a meshgrid in Matlab?

A meshgrid in Matlab is a two-dimensional grid of points that is used to evaluate functions and create plots.

2. How do I create a meshgrid in Matlab?

To create a meshgrid in Matlab, you can use the meshgrid function. This function takes in two vectors representing the x and y coordinates and returns two matrices representing the x and y coordinates of each point on the grid.

3. What is the purpose of using a meshgrid in Matlab?

A meshgrid is useful for evaluating functions on a grid of points and creating visual representations of these functions using plots. It is commonly used in scientific and engineering applications to analyze data and visualize results.

4. How do I use a meshgrid to plot a function in Matlab?

To plot a function using a meshgrid in Matlab, you can first create the meshgrid using the meshgrid function. Then, you can use the surf function to create a three-dimensional surface plot or the pcolor function to create a two-dimensional color map of the function.

5. Can a meshgrid be used to interpolate data in Matlab?

Yes, a meshgrid can be used to interpolate data in Matlab. This can be done using the interp2 function, which takes in a meshgrid and a set of data points and returns interpolated values for any desired point on the grid.

Similar threads

  • Introductory Physics Homework Help
Replies
11
Views
762
  • Classical Physics
Replies
10
Views
700
  • Precalculus Mathematics Homework Help
Replies
23
Views
3K
  • Special and General Relativity
Replies
12
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
3
Views
1K
Replies
2
Views
2K
  • Introductory Physics Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top