Function with matrices as output and input

1 次查看(过去 30 天)
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 :)

回答(1 个)

Star Strider
Star Strider 2016-3-21
编辑:Star Strider 2016-3-21
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.

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by