using ODE45 when parameters in my function change in time?
古いコメントを表示
Hi,
I am using ode45 to simulate a model of a mass linked to a pivot through a spring. Radial force and torque are applied and can change in time.
I used previously ode45 with equations that do not change in time, by creating a function eg dtheta= fn (t, theta) as suggested on Mathworks. I am not sure how to do with variable parameters though.
This is my code:
function [ dtheta ] = leg( t,theta)
% theta (1) is theta, Theta (2) is angular velocty
m=1;
g=9.8;
tau=0;
f=0;
k=500;
r0=0.01;
dtheta=zeros(2,1);
dtheta(1)=theta(2);
dtheta(2)=tau/m+g*sin(theta(1))*( (f - m*g*cos(theta(1)))/k +r0 );
end
which I will call with
close all
t0=0;
tf=10;
theta0=pi/2;
angvel0=0;
[T,THETA] = ode45(@leg,[t0 tf],[theta0 angvel0]);
plot(T,THETA(:,1))
xlabel('time')
ylabel('theta (radians)');
Right now I am simulating the model with 0 torque and 0 radial force. As well I could simulate it with constant torque and force. But I need them to change in time (eg being vectors in time). How do I do that?
Thanks!!! Cristina
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!