Multiple outputs in function not showing.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to write a function for calculating the fixed point iteration for a system of 2 equations. Although my function works it only displays the x-output. My code is below:
%%Solves a system of 2, 2 variable equations using the fixed point
%%iteration method.
%Fx=function of two variables of the form x=g(x,y)
%Fy=function of two variables of the form y=g(x,y)
%Xest=initial estimate for x-value of root
%Yest=initial estimate for y-value of root
%imax=number of iterations
%Xs=output of FixedIterationRoot, stores all values of x.
%Ys=output of FixedIterationRoot, stores all values of y.
function [Xs , Ys]= FixedIterationRoot_sys2(Fx,Fy,Xest,Yest,imax)
Xi(1)=Xest;
Yi(1)=Yest;
syms x y
dFx=diff(Fx,x);
dFy=diff(Fy,y); %finds derivative of Fun
if abs((subs(dFx,Xest))+abs(subs(dFy,Yest)))>=1 %Stating the condition of convergence.
disp('Error: algorithm does not converge')
return
else
for i=2:imax % Calculating the solutions to fixed point equation.
Xi(i)=subs(Fx,[x,y],[Xest,Yest]);
Yi(i)=subs(Fy,[x,y],[Xest,Yest]);
Xest=Xi(i);
Yest=Yi(i);
end
end
Xs=Xi;
Ys=Yi;
end
0 comentarios
Respuestas (1)
Steven Lord
el 26 de Abr. de 2017
Defining a function to return multiple outputs is necessary but not sufficient to have that function return multiple outputs. You also need to call it with multiple outputs.
For instance, the max function is defined to return up to two outputs. If you ask it for one, it will return one. If you ask it for two, it will return two. If you ask it for three, it will throw an error.
x = 1:10;
theMaximum = max(x)
[theMaximum2, location2] = max(x)
0 comentarios
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!