# Using condition in Function

4 views (last 30 days)
F.O on 15 Nov 2017
Answered: Walter Roberson on 16 Nov 2017

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

Image Analyst on 16 Nov 2017

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

### Categories

Find more on Tables in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!