Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to get second derivatives using ode45
Replies: 4   Last Post: Apr 30, 2013 11:15 AM

 Messages: [ Previous | Next ]
 stanley ontario Posts: 3 Registered: 4/30/13
Re: How to get second derivatives using ode45
Posted: Apr 30, 2013 11:15 AM

> For i=1:numel(t_vec)
> y(1)=Y(i,1);
> y(2)=Y(i,2);
> y(3)=Y(i,3);
> y(4)=Y(i,4);
> t=t_vec(i);
> dy=vib_equ(t,y,c_s_f,c_s_r,v_val,F_d_val,m_c,I_g_c,l,l_f,l_r,u_f,u_f_dot,v,L,i_d);
> Y_acc(i,1) = dy(2);
> Y_acc(i,2) = dy(4);
> end
>
> does not work ?
>
> (Of course you will have to supply the correct values for the variables in your calling list to vib_equ)
>
> Or use the OutputFcn facility during the computation with ode45.
>
> Best wishes
> Torsten.

I understand your code, however I have a matrix dimension error now.
Here's what it looks like inside the function:
function dy = vib_equ(t,y,c_s_f,c_s_r,v_val,F_d_val,m_c,I_g_c,l,l_f,l_r,u_f,u_f_dot,v,L,i_d);

z_cf=y(1);
z_cf_dot=y(2);
z_cr=y(3);
z_cr_dot=y(4);

v_vec=linspace(-1.04,1.04,100);
v_d_f= (z_cf_dot-u_f_dot(t,L,v))/i_d;
v_d_r= (z_cr_dot-u_f_dot(t-l/v,L,v))/i_d;

F_dw_f= interp1(v_val,F_d_val,v_d_f,'spline');
F_dw_r= interp1(v_val,F_d_val,v_d_r,'spline');

K1=(1+(m_c*l_f^2)/I_g_c);
K2=(1-(m_c*l_f*l_r)/I_g_c);
K3=(1+(m_c*l_r^2)/I_g_c);
K4=K2;

MC= [m_c 0; 0 m_c];
A= [-K1*c_s_f 0 -K2*c_s_r 0; -K4*c_s_f 0 -K3*c_s_r 0];
B= [-K1/i_d*F_dw_f+K1*c_s_f*u_f(t,L,v)-K2/i_d*F_dw_r+K2*c_s_r*u_f((t-l/v),L,v); -K3/i_d*F_dw_r+K3*c_s_r*u_f((t-l/v),L,v)-K4/i_d*F_dw_f+K4*c_s_f*u_f(t,L,v)];
C= inv(MC)*A;
D= inv(MC)*B;

z_ddot=C*y+D;

dy= zeros(4,1);
dy(1)= y(2);
dy(2)= z_ddot(1);
dy(3)= y(4);
dy(4)= z_ddot(2);

And I have an error at z_ddot=C*y+D because of the matrix dimensions now.

I really don't understand why.

Date Subject Author
4/30/13 stanley ontario
4/30/13 Torsten
4/30/13 stanley ontario
4/30/13 Torsten
4/30/13 stanley ontario