Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Ode45 error

Subject: Ode45 error

From: grex91

Date: 1 May, 2013 09:46:09

Message: 1 of 3

Ehi, i'm trying so solve a problem with ode45 but it gives me an error that i don't understand (i'm pretty new in matlab or any kind of programming).

here is the main code:
k= 20; %1/s
t= linspace(0,4,100);


for i=1:100
 
    F_bf= inline('F_bf_max*(1-exp(-k*t))','t','k','F_bf_max');
    F_bf_vector(i)=F_bf(t(i),k,F_bf_max);
    F_br_vector(i)=F_bf_vector(i)*(1-k_b)/k_b;
    

end
 
figure
plot(t,F_bf_vector,'linewidth',2);
title('Braking force as function of time');
xlabel('Time [s]');
ylabel('Frontal braking force [N]');



%% Task 6

m= 1100; %Kg
Ig= 1500; %Kg*m^2
l= 2.5; %m
lf= 1.1;%m
lr= l-lf; %m
h= 0.5; %m
cf= 10; %KN/m
cr= 10; %KN/m
df= 1.0; %KN*s/m
dr= 1.0; %KN*s/m
rho= 1.226; %Kg/m^3
Af= 2.15; %m^2
cd= 0.29;
c_Lf= 0.13;
c_Lr= 0.10;

t_max=4; %s
v_start= 100/3.6; %m/s


    
    options= odeset('RelTol',1e-3,'AbsTol',1e-6);
[t_vec,Y]=ode45(@(t,y) equ_task6(t,y,m,Ig,l,lf,lr,h,cf,cr,df,dr,rho,Af,cd,c_Lf,c_Lr,v_start,F_bf,k,k_b,F_bf_max),[0 t_max],zeros(1,6),options);


    x= Y(:,1)
    x_dot= Y(:,2);
    phi= Y(:,3);
    phi_dot= Y(:,4);
    z= Y(:,5);
    z_dot= Y(:,2);



And here is the function, i think the problem is related to "b2" but i don't understand why...

function dy= equ_task6(t,y,m,Ig,l,lf,lr,h,cf,cr,df,dr,rho,Af,cd,c_Lf,c_Lr,v_start,F_bf,k,k_b,F_bf_max)

x=y(1);
x_dot=y(2);
phi=y(3);
phi_dot=y(4);
z=y(5);
z_dot=y(6);

F_b_f=F_bf(t,k,F_bf_max);
F_b_r=F_b_f*(1-k_b)/k_b;


Fd= 0.5*rho*Af*cd*((y(2)+v_start)^2);
F_Lf= 0.5*rho*Af*c_Lf*((y(2)+v_start)^2);
F_Lr= 0.5*rho*Af*c_Lr*((y(2)+v_start)^2);

b1= -F_b_f-F_b_r-Fd;
b2= Fd*h-F_Lf*lf+F_Lr*lr+h(F_b_f+F_b_r)-F_b_f*0.15*lf-F_b_r*0.3*lr;
b3= F_Lf+F_Lr+F_b_f*0.15-F_b_r*0.3;

M=[m 0 0; 0 Ig 0; 0 0 m];
A=[0 0 0 0 0 0; 0 0 lf*cf-lr*cr lf*df-lr*dr -(cf+cr) -(df+dr); 0 0 -((lf^2)*cf+(lr^2)*cr) -((lf^2)*df+(lr^2)*dr) lf*cf-lr*cr lf*df-lr*dr];
B=[b1; b2; b3];

C=M\A;
D=M\B;

acc=C*y+D;

dy= zeros(6,1);
dy(1)= y(2);
dy(2)= acc(1);
dy(3)= y(4);
dy(4)= acc(2);
dy(5)= y(6);
dy(6)= acc(3);



Thanks for any help!

Subject: Ode45 error

From: Steven_Lord

Date: 1 May, 2013 13:38:45

Message: 2 of 3



"grex91 " <gregorio.riva@hotmail.it> wrote in message
news:klqo91$re$1@newscl01ah.mathworks.com...
> Ehi, i'm trying so solve a problem with ode45 but it gives me an error
> that i don't understand (i'm pretty new in matlab or any kind of
> programming).

*snip*

What is the exact and full text of the error that you receive when you run
this code? I attempted to run the code but several variables were missing
from what you posted (I stopped after MATLAB reported that F_bf_max and k_b
were undefined.) If you post the error message and/or the definition for all
the variables that need to be defined to run this code to the group (please
do NOT send them to me directly) someone may be able to offer a suggestion
how to correct the problem causing the error.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Ode45 error

From: grex91

Date: 1 May, 2013 15:55:09

Message: 3 of 3

yeha sorry, here is the first part of the code that was missed:

g= 9.81; %m/(s^2)
k_b= 0.7;
m= 1100/2; %Kg
r= g*0.8; %m/(s^2)

F_bf_max= m*r*k_b

This is the beginning, to be put above the code in my first post...


"Steven_Lord" <slord@mathworks.com> wrote in message <klr5t4$9tu$1@newscl01ah.mathworks.com>...
>
>
> "grex91 " <gregorio.riva@hotmail.it> wrote in message
> news:klqo91$re$1@newscl01ah.mathworks.com...
> > Ehi, i'm trying so solve a problem with ode45 but it gives me an error
> > that i don't understand (i'm pretty new in matlab or any kind of
> > programming).
>
> *snip*
>
> What is the exact and full text of the error that you receive when you run
> this code? I attempted to run the code but several variables were missing
> from what you posted (I stopped after MATLAB reported that F_bf_max and k_b
> were undefined.) If you post the error message and/or the definition for all
> the variables that need to be defined to run this code to the group (please
> do NOT send them to me directly) someone may be able to offer a suggestion
> how to correct the problem causing the error.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us