Results showing up as NaN

11 visualizaciones (últimos 30 días)
Alexandru Bortea el 19 de Abr. de 2017
Comentada: Andrew Newell el 20 de Abr. de 2017
I have been working on a launch control simulation and something happened recently because the matrix z is returning only NaN values now... I do not remember changing anything in the script or the function. I have also attached below the main function used with the code... maybe you spot a mistake there...
global m g I h lR lF r LCREV_MAX LCSPEED_MAX
LCREV_MAX = 12000;
LCSPEED_MAX = 35;
m = 295; % mass of vehicle including driver
g = 9.81; % gravitational acceleration
r = 0.23; % wheel radius
I = 0.2645; % tyre moment of inertia
h = 0.28; % CoG height
lR = 0.765; % Distance of CoG to rear axle
lF = 0.765; % Distance of CoG to front axel
z10 = 0; % initial x position
z20 = 0; % initial linear velocity
z30 = 0; % initial angle of rear wheel
z40 = 0; % intial angular velocity of rear wheel
z0 = [z10 z20 z30 z40]; % initial conditions vector
t0 = 0; % intial time
tf = 6; % final time
[t,z] = ode45('LC_eom',(t0:0.1:tf),z0);
x = z(:,1); % position as first column of z matrix
v = z(:,2); % linear velocity as second column of z matrix
theta = z(:,3); % angle as third column of z matrix
omega = z(:,4); % angular velocity as fourth column of z matrix
8 comentariosMostrar 6 comentarios más antiguosOcultar 6 comentarios más antiguos
Andrew Newell el 20 de Abr. de 2017
Editada: Andrew Newell el 20 de Abr. de 2017
One reason you may be using global variables is that ode45 expects a function with two variables. However, that is easily handled using anonymous functions. For example, the function LC_eom needs m, I and r in addition to t and z. However, these are just parameters that (I presume) aren't changing while ode45 is running. You can define
function dz = LC_eom (t,z,m,I,r,)
in LC_eom.m and then, LCS.m, define
fun = @(t,z) LC_eom(t,z,m,I,r);
and use that in ode45:
[t,z] = ode45(fun,(t0:0.1:tf),z0);
Alexandru Bortea el 20 de Abr. de 2017
Thank you very much for all the answers, I'll try to remove all global parameters and individually use them in the functions.

Iniciar sesión para comentar.

Andrew Newell el 20 de Abr. de 2017
Here is one source of NaN's: In slipratio_fun with the initial value of t=0 and v=0, you have omega=v=0. The line
sx (abs(omega)*r>=abs(v)) = -1 + v./(omega.*r); % acceleration
sets sz equal to NaN because it's dividing by zero.
7 comentariosMostrar 5 comentarios más antiguosOcultar 5 comentarios más antiguos
Alexandru Bortea el 20 de Abr. de 2017
I should be able to deal with it myself! Thank you very much for helping me with the code part!!!
Andrew Newell el 20 de Abr. de 2017

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by