Translating Trig Expressions into Code

1 Ansicht (letzte 30 Tage)
Stephanie Goldstein
Stephanie Goldstein am 22 Aug. 2014
Hello everyone! I am a beginner at matlab and am attempting to calculate the area of each individual grid cell of climate data. I know that the area can be calculated with ((2*pi*R)/360)^2)*cos(theta)*delta_latitude*delta*longitude but am lost as to how to translate this into code. Can anyone offer suggestions please?
  2 Kommentare
Joseph Cheng
Joseph Cheng am 22 Aug. 2014
Bearbeitet: Joseph Cheng am 22 Aug. 2014
well unless there is something complicated what you typed in should work. if any of those are an array (more than 1x1) then you may want to look into the element by element multiplication '.*'
also did you make a typo? should it be delta_longitude?
((2*pi*R)/360)^2)*cos(theta)*delta_latitude*delta_longitude
and make sure theta is in radians or use cosd() for cosine with input of degrees.
Stephanie Goldstein
Stephanie Goldstein am 22 Aug. 2014
Hmm the only problem is that when I put this into matlab I get the error "Error using * Inner matrix dimensions must agree." Any clue as to how to fix this?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Roger Stafford
Roger Stafford am 22 Aug. 2014
Your formula is only a valid approximation if the two delta's are small and are measured in degrees. Also theta must be the latitude. If it is measured in degrees, in matlab you would use either cosd(theta) or cos(theta*pi/180). Otherwise you can copy it directly into a matlab assignment.
  3 Kommentare
Roger Stafford
Roger Stafford am 22 Aug. 2014
Bearbeitet: Roger Stafford am 22 Aug. 2014
Yes, that would produce a complaint from matlab. If you have a 224 x 1 size vector first multiplied by a 1 x 240 size vector second, it would give you a 224 x 240 matrix of products. Is that what you are after? You haven't adequately explained what you are really attempting to do.
Stephanie Goldstein
Stephanie Goldstein am 25 Aug. 2014
Hi Roger, I'm attempting to find the area of each grid cell using latitude and longitude arrays which are 224 X 1 and 240 X 1 respectively. Does this help at all? How would I go about calculating the area using the formula I initially gave when the two vectors I am using differ in size? Thanks.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 22 Aug. 2014
Bearbeitet: Image Analyst am 22 Aug. 2014
I think you both made a typo. There should be no ) after the R. You have three ( and four ).
degreeToRadiansConversionFactor = pi / 180; % Call it out so people know what it is.
area = (R * degreeToRadiansConversionFactor)^2 * delta_latitude * delta_longitude;
I also took out the cos(theta) since I don't know why it's there. Since the arc length on the surface of a circle is S=R*theta, if the patch is rectangular, you'd get an area of length * width = R^2 * delta_latitude * delta_longitude, where delta_latitude & delta_longitude are in radians, so where do you get the cos(theta) from?
  6 Kommentare
Roger Stafford
Roger Stafford am 22 Aug. 2014
@Image Analyst. If you have ever used USGS topographical maps, you will note that maps in the U.S. of the seven-and-a-half-minute series are not squares but are rectangles, even though the two angle delta's are the same. That illustrates the need for the cosine correction.
Stephanie Goldstein
Stephanie Goldstein am 25 Aug. 2014
Alright, thanks for clearing that up Roger!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Purple finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by