Function with matrices as output and input
1 view (last 30 days)
Show older comments
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 :)
Answers (1)
Star Strider
on 21 Mar 2016
Edited: Star Strider
on 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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!