Hey guys! This is my first time using this function, and although I have tried to make it work, the program is not running due to some errors I cannot understand Could any of you please help me?
Here is my main code for the function I am trying to analyze.
function dxdt = nonlinear_quarter(t,x)
w = 0.03*(heaviside(t)-heaviside(t-pi)).*(sin(10*t));
g=9.81;
m1 = 290;
m2 = 59;
k1 = 16812;
k2 = 190000;
b1 = 1000;
alfa=4.515*(10^13);
beta=1;
gama=1.545*(10^9);
tau=(1/30);
Ps=10342500;
A=3.35*(10^(-4));
dxdt=zeros(6,1);
dxdt(1) = x(2);
dxdt(2) = -(k1/m1)*x(1)-(b1/m1)*x(2)+(k1/m1)*x(3)+(b1/m1)*x(4)+(A/m1)*x(5);
dxdt(3) = x(4);
dxdt(4) = (k1/m1)*x(1)+(b1/m2)*x(2)-((k1+k2)/m2)*x(3)-(b1/m2)*x(4)-(A/m2)*x(5)+(k2/m2)*w;
dxdt(5) = -alfa*A*x(2)+alfa*A*x(4)-beta*x(5)+gama*x(6)*sqrt(Ps-x(5)*sign(x(6)));
dxdt(6) = -(1/tau)*x(6)-(1/tau)*((K(1))*x(1)+(K(2))*x(2)+(K(3))*x(3)+(K(4))*x(4)+(K(5))*x(5)+(K(6))*x(6));
This function is then called by the following function:
function [t,x]=call_nonlinear_quarter()
x0 = [0 0 0 0 0 0]';
tspan=[0 5];
opts = odeset('RelTol',1e-2,'AbsTol',1e-4);
[t,x] = ode45(@nonlinear_quarter, tspan, x0,opts);
After running this second function I get the following mistakes:
Error in nonlinear_quarter (line 21)
dxdt(6) = -(1/tau)*x(6)-(1/tau)*((K(1))*x(1)+(K(2))*x(2)+(K(3))*x(3)+(K(4))*x(4)+(K(5))*x(5)+(K(6))*x(6));
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in call_nonlinear_quarter (line 5)
[t,x] = ode45(@nonlinear_quarter, tspan, x0,opts);
Does anyone knows why that is happenning?
Thank you all very much

 Réponse acceptée

Star Strider
Star Strider le 24 Juin 2016

0 votes

When I run your code, I get:
Undefined function or variable 'K'.
You need to define your special ‘K’ vector.

2 commentaires

Allan Andre do Nascimento
Allan Andre do Nascimento le 25 Juin 2016
Thanks!
Star Strider
Star Strider le 25 Juin 2016
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by