Using condition in Function

4 ビュー (過去 30 日間)
F.O
F.O 2017 年 11 月 15 日
回答済み: Walter Roberson 2017 年 11 月 16 日

Hei. I have this script:

%% Problem 3
clear all
%a)
%DATA for Nazca-Pacific 
o1=13.6*10^-7
l1=55.6
ph1=-90.1
%DATA for Pacific-Antarctica 
o2=8.7*10^-7
l2=-64.3
ph2=96
[omeganew,lambdanew,phinew] = geofun( o1,l1,ph1,o2,l2,ph2)
%phinew1=phinew1-180
%b)
%From Table 2.1 in Fowler Book We choose Africa-North America and Africa-
%south America plate pairs because they have a common boundary
%Data for Africa-South America
SwA=3.1*10^-7 ; %Degree/yr
latSA=62.5;     %Degree
longSA=-39.4;
%Data for Africa-North America(The angular velocity  is given for North
%America relative to Africa and we get for Africa relative to North America
%just by change the sign)
NwA=2.4*10^-7;
AwN=-2.4*10^-7;
latAN=78.8;
longAN=38.3;
[SwN,latSN,longSN] = geofun( SwA,latSA,longSA,AwN,latAN,longAN)

and this function

function [ omeganew,lambdanew,phinew] = geofun( o1,l1,ph1,o2,l2,ph2)
%Using known rotation vector data from two pairs of plates to find the
%‘unknown’ rotation vector data of another pair of plates (using Table 2.1)
2.1
x=o1*cosd(l1)*cosd(ph1)+o2*cosd(l2)*cosd(ph2)
y=o1*cosd(l1)*sind(ph1)+o2*cosd(l2)*sind(ph2)
z=o1*sind(l1)+o2*sind(l2)
omeganew=sqrt(x^2+y^2+z^2)
lambdanew=asind(z/omeganew)
phinew=atand(y/x) 
end

How I will add a condition to the function or where I should put the condition

the condition is If x> 0 then -90<phinew<90 otherwise we subtract 180 from phinew and ifx<0 then the absoloute value of phinew should be greater than 90 otherwise we subtract 180 from phinew

  1 件のコメント
Image Analyst
Image Analyst 2017 年 11 月 16 日
Try this http://www.mathworks.com/matlabcentral/answers/13205#answer_18099 so your post won't go into the spam quarantine next time. I've rescued your post this time.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 16 日
Use atan2d(y, x) instead of atand(y/x) and you will probably not need to make any angle correction.

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by