If we need to run the same algorithms or formula for computations again and again, then instead of writing the same stuffs in our script file many times, we can simply write a function. This makes our script look simpler and faster to run.
Examples:
Calculating mean and standard deviation
Calculating distance from origin
Calculates distance (in km) between two coordinate points on the Earth’s surface
—Utpal Kumar (IES, Academia Sinica)
This might be very basic. But following the function logic I wrote this:
phi = 0:1:90
sin_phi= sind (phi);
K = (sin_phi/(1-sin_phi))
Results show only one K. I want all of the K’s for all of the Phi’s.
May I ask a hint where to go then?
Thanks!!!
LikeLike
@Rocio: Here, your variable sin_phi is an array. In MATLAB, for division with an array, the operator “./” is used instead of “/”. Here, you need to change K = (sin_phi./(1-sin_phi)) to get an array output.
LikeLiked by 1 person
Thanks codethedata!
I’ll will move forward with my exercise then. I skipped continuing with the problem, now I’ll go back to it.
LikeLike