Finding a parameter that solves the ODE45 to set conditions
1 view (last 30 days)
Show older comments
I am trying to solve an ode45 of a mass spring system that will calculate the spring stiffness constant such that the motion of mass a meets set conditions. Currently I have defined K as a set value. Below is my ode function that solves the equations of motion.
function 2massspring
% implement Mass B mg creating a moment around support
% define time
tspan = linspace(0,10,1000);
%define initial conditions [a0; adot0; b0; bdot0]
fa = 0.4; % forearm length A
fb = 0.45; % forearm length B
ba = 0.3; % bicep length A
bb = 0.35; %bicep length B
i0 = [-(fa+fb+ba+bb)/2;0;(fa+fb+ba+bb)/2;0];
%solve for x
[t,z] = ode45(@IF, tspan, i0);
%define output variables
a = z(:,1);
adot = z(:,2);
b = z(:,3);
bdot = z(:,4);
%plotting functions
subplot(2,1,1);
plot(t,a,'g',t,b,'r');
ylabel('Mass A Green Mass B Red');
xlabel('time');
subplot(2,1,2);
plot(t,adot,'g',t,bdot,'r');
ylabel('Mass Adot Green Mass Bdot Red');
function dzdt = IF(t,z)
%integratingfunction is vector of 1st order ODE
% define the variables
a = z(1);
adot = z(2);
b = z(3);
bdot = z(4);
Ma = 70.2; %Kg
Mb = 86; %Kg
k1 = 1000; %n/m
%create an array the same length as z
dzdt = zeros(size(z));
dzdt(1) = adot;
dzdt(2) = (k1/Ma)*(b-a);
dzdt(3) = bdot;
dzdt(4) = -(k1/Mb)*(b-a);
end
end
i would like to simultaneously solve the ODEs with an initial guess of a K value but or the K value to be updated to fit conditions such as the time it takes to reach max speed and also the value of the max speed, producing a final K value that meets these conditions. could anyone help me to do this? i have tried going through an ode example of the Lorenz but i do not understand how to apply that to my problem. any help would be greatly appreciated, thanks.
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!