MATLAB: Using a variable as both output and input and writing a condition in a function

assignmentMATLAB

Hei , I have this function
function [lambda, lambdap,phip] = Palaeomagfun(I ,D,lambda,lambdax,phix )
lambda=atand(tand(I)/2) %in degree
lambdap=asind(sind(lambdax)*sind(lambda)+cosd(lambdax)*cosd(lambda)*cosd(D))
if sind(lambda)>=sind(lambdap)*sind(lambdax)
phip=phix+asind(cosd(lambda)*sin(D)/cosd(lambdap))
elseif sind(lambda)<sind(lambdap)*sind(lambdax)
phip=phix+asind(cosd(lambda)*sind(D)/cosd(lambdap))-180
end
and this script
Problem 2:
I=30
lambdax=47
phix=20
D=80
[lambda, lambdap,phip] = Palaeomagfun(I ,D,lambda,lambdax,phix )
*first,Is it possible to use lambda as an output and input at the same time or i need two function or something else?
second: is my if coding correct in the function?*

Best Answer

When you write
function [lamda, lambdap,phip] = Palaeomagfun(I ,lamda,lamdax,phix )
lamda=atand(tand(I)/2) %in degree
the input lamda you pass would be overwritten because of your first line inside the function.
How about using two variables, say lamda_in and lamda_out
function [lamda_out, lambdap,phip] = Palaeomagfun(I ,lamda_in,lamdax,phix )