Function with matrices as output and input
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I am asking for help with plotting 3 outputs of function as Ys with input as X.
My algorithm for the function is
function [u,v,w]= g5(t)
A=[6 9 15
-5 -10 -21
2 5 11];
S=[1;2;3];
for f=t
U=expm(A*f)*S;
end
U
I want input to be I=0:0.01:1.
Thanks :)
Réponses (1)
Star Strider
le 21 Mar 2016
Modifié(e) : Star Strider
le 21 Mar 2016
This would be my approach:
function U = g5(t)
A=[6 9 15
-5 -10 -21
2 5 11];
S=[1;2;3];
for f=1:length(t);
ti = t(f);
U(:,f)=expm(A*ti)*S;
end
end
Then in your calling script:
I=0:0.01:1;
U = g5(I);
figure(1)
plot(I, U)
grid
I didn’t include ‘v’ and ‘w’ in the output arguments because you didn’t define them in your code. Add them when you do.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!