How can I stop a user defined function from returning the output twice?
Mostrar comentarios más antiguos
The function seems to be looping twice. I cannot see how the code allows this.
Code:
function [ x,solution,logical ] = sim_eq( A,b )
%SIM_EQ solves a system of simultaneous equations.
% Calculate rank and solve
n=input('Input number of unknowns:');
m=input('Input number of equations:');
r1=rank(A);
r2=rank([A b]);
if r1==r2 && r1==n && r2==n
if m>n
display('Overdetermined set of equations. Least-squares fit.');
x=A\b
solution= 'Unique'
logical= 'Approximate'
elseif m==n
x=A\b
solution= 'Unique'
logical= 'Exact'
end
elseif r1==r2 && r1<n && r2<n
x=pinv(A)*b
solution= 'A solution'
logical= 'Exact'
elseif r1~=r2
x= 'No solution'
solution= 'nil'
logical= 'nil'
end
end
3 comentarios
dpb
el 22 de Mzo. de 2015
Seems to just sit there afaict... :)
Show us what you think the issue is specifically, don't make us try to dream it up...
craig
el 23 de Mzo. de 2015
dpb
el 23 de Mzo. de 2015
I had to format the code and admit I then didn't actually read it...hadn't thought it so simple a question... :)
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Get Started with MuPAD en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!