Numerically Solving a System of Differential Equations Using a First-Order Taylor Series Approximation
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I don't need specific code corrected for me (nor do I have any to show currently), just some guidance (and to see if what I need is even possible). I have a system of second-order differential equations (y'',y',y,z'',z',z) and all of their initial values which I have printed below. All non-bold letters are known constants (the functions are y'',y',y,z'',z',z; all are a function of time. At the end is the approximation to be used.
*the first instance of g in the first equation (at the start of the square brackets) should be a J
I am required to plot y and z and continue the calculations for this approximation process until y = pi, where the approximations then stop. I would then like to take the y value at this point (pi) and the z value at this point and then plug them into this equation (g is not a function)
Once this done, I can change the parameter e in those equations to e+dm for dm some very small increment, and then repeat the exact same process up to some value. At the end of this process I should have be able to have graphs for y and z against time and a graph for v_p against the e+dm values (mass).
My question is: What are some of the functions in MatLab I will need to know of to complete this task and how exactly would something like this be structured? I'm assuming something like this is actual doable in MatLab, at least.
5 commentaires
Ameer Hamza
le 18 Juin 2018
It seems that you are working in the correct direction but your model function should also return four derivatives. Try my answer below to see the if it works.
Réponse acceptée
Ameer Hamza
le 18 Juin 2018
You will need to introduce extra variables to convert the 2nd order equations to first order. I have assumed the following variables
y_dot = y1
z_dot = z1
From this I have
y_dotdot = y1_dot
z_dotdot = z1_dot
put y1_dot in place of y_dotdot and z1_dot in place of z_dotdot to get a first order system.
In the following code, i have assumed all the constants to be 1 and also the initial condition y(0) = 1, remaining initial conditions are zero.
Save the following function in your MATLAB path
function dydt = odefun(t, y) % y = [y z y1 z1]
[a,b,c,d,e,f,g,h,J] = deal(1);
dydt = zeros(4,1);
dydt(1) = y(3); % y_dot = y1
dydt(2) = y(4); % z_dot = z1
dydt(3) = (J*(a*b-c*d-e*f)*sin(y(1)) + e*f*J*sin(dydt(2))*sin(y(1)-y(2)) - f*dydt(1).^2*cos(y(1)-y(2))*sin(y(1)-y(2)))/...
(a*b^2 + 1/12*c*(f+b)^2 + c*h^2 + e*f^2*sin(y(1)-y(2))^2);
dydt(4) = (f*(dydt(1)^2*sin(y(1)-y(2)) - dydt(3)*cos(y(1)-y(2))) - J*sin(y(2)))/...
g;
end
and then run the following line;
[t,y] = ode45(@odefun, [0 pi], [1 0 0 0]);
plot(t,y,'-o')
The y will contain four columns, first for values of y and second for values of z, whereas 3rd and 4th are for the value of y1 and z1.
3 commentaires
Ameer Hamza
le 18 Juin 2018
The first thing you mentioned is a warning, not error. You can suppress it by writing it like this
function dydt = odefun(~, y) % y = [y z y1 z1]
Also, you don't need to write
y_dot = y1;
z_dot = z1;
y_dotdot = y1_dot;
z_dotdot = z1_dot;
I wrote those lines just for explanation. Delete these lines and then run the code.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!