How to use ode45 for a row vector

function v = f(t,x);
zeta=0.9
m=5; k=1000;
c=2.*zeta.*sqrt(m*k);
v=[x(2); x(1).*-k/m+x(2).*-c./m];
end
and
clear all
xo=[0.05; 0];
ts=[0 3];
[t,x]=ode45('f',ts,xo);
figure(1)
plot(t,x(:,1))
I was wondering how I can make this plot work with multiple zeta values
zeta=[0, 0.1, 0.25, 0.5, 0.75, 0.9, 1];

답변 (2개)

madhan ravi
madhan ravi 2020년 3월 29일

1 개 추천

Parametrization and loop through zeta.

댓글 수: 3

how would i go about the loop?
clear all
xo=[0.05; 0];
ts=[0 3];
[t,x]=ode45(@myfun,ts,xo);
figure(1)
plot(t,x(:,1))
function v = myfun(t,x);
zeta=0.9
m=5; k=1000;
c=2.*zeta.*sqrt(m*k);
v=[x(2); x(1).*-k/m+x(2).*-c./m];
end
would it be before the function and contain whats in the first block of code?
xo=[0.05; 0];
ts=[0 3];
zeta = ... values;
na = sprintfc('zeta=%.2f',zeta); % use compose() in later versions
for zeta = zeta
[t,x]=ode45(@(t,x)myfun(t,x,zeta),ts,xo);
plot(t,x(:,1))
hold on
end
function v = myfun(t,x,zeta)
m=5; k=1000;
c=2.*zeta.*sqrt(m*k);
v=[x(2); x(1).*-k/m+x(2).*-c./m];
end
Erik Sharrer
Erik Sharrer 2020년 3월 30일
what does 'zeta=%.2f' mean?

댓글을 달려면 로그인하십시오.

Steven Lord
Steven Lord 2020년 3월 29일

0 개 추천

See the "Pass Extra Parameters to ODE Function" example on the documentation page for the ode45 function. You can use it as a model for your code.

댓글 수: 1

Erik Sharrer
Erik Sharrer 2020년 3월 29일
I still would need to use a loop though right?

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

2020년 3월 29일

댓글:

2020년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by