DOUBLE SPRING MASS SYSTEMS & MATLAB’S ODE 45
Afficher commentaires plus anciens
Hello I'm having difficulties running this program. I would like to move I don't know if any other command line is missing. To run the values and graph.
function [xDot] = doubleSpringMass(t,X,args)
%State space fucntion of Double Spring Mass System
%Made for insert link to gereshes here %Ari Rubinsztejn
%2018.12.22
x1=X(1);
x2=X(2);
k1=args(1);
m1=args(2);
k2=args(3);
m2=args(4);
F1=(-k1*x1)+(k2*(x2-x1));
F2=(-k2*x2)+(k2*x1);
x1DD=F1/m1;
x2DD=F2/m2;
xDot=[X(3),X(4),x1DD,x2DD];
end
Réponses (1)
Sulaymon Eshkabilov
le 5 Sep 2021
There are a few errs in your code. Here is the corrected and complete code:
t=[0, 3];
X0 = [1; 3; 0 ;0];
OPTs =odeset('OutputFcn', @odeplot, 'reltol', 1e-3, 'abstol', 1e-5);
ode45(@doubleSpringMass, t, X0, OPTs)
legend('Mass 1: x_1(t)', 'Mass 2: x_2(t)', 'Mass 1: dx_1(t)', 'Mass 2: dx_2(t)')
function DX = doubleSpringMass(t,X)
args = [10, 2, 20, 3];
k1=args(1);
m1=args(2);
k2=args(3);
m2=args(4);
dx(1)=X(2);
dx(2)=(1/m1)*(-k1*X(1))+(k2*(X(3)-X(1)));
dx(3)=X(4);
dx(4)=(1/m2)*(k1*X(1))-(k2*X(3));
DX=[dx(1); dx(2); dx(3); dx(4)];
end
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!