Error when solving differential equations
Afficher commentaires plus anciens
function dydt = vdpi1(t,y)
syms n
a=3.5*10^-6;
Gm=0.02
Sp=2.75*10^-5;
yon=0.01;
b=3.1;
son=0.10;
B=90;
% vm=0:0.5:2.5;
% gp=sinh(vm);
A=2.5;
soff=0.07;
beta=300;
yoff=0.091
v=symsum((1/n)*sin(2*n*pi*20*t),n,1,100)
i=v.*(y(1)*Gm+(1-y(1))*a.*exp(b*sqrt(abs(v))))
p=v.*(y(1)*Gm+(1-y(1))*a.*exp(b*sqrt(abs(sin(t))))).*v
dydt1 = B*sinh(v/son).*exp(-y(1).^2/yon^2).*exp(p/Sp)*heaviside(t)
% p1=v.*(y(2)*Gm+(1-y(2))*a.*exp(b*sqrt(abs(sin(t))))).*v
dydt2=A*sinh(v/soff).*exp(-yoff^2./y(2).^2).*exp(1/(1+beta*p))
dydt=[dydt1;dydt2]
[t,y] = ode45(@vdpi,[-10 10],[0.1,0.02]);
% Plot the solutions for $y_1$ and $y_2$ against t.
Gm=0.02
Sp=2.75*10^-5;
yon=0.01;
b=3.1;
son=0.10;
B=90;
plot(t,y(:,1))
k=real(i)
k(41:44)=[]
% v=sin(t);
figure
plot(t,y(:,2))
% plot(v,-k)
i am getting error :
Error using odearguments (line 95)
VDPI returns a vector of length 1, but the length of initial conditions vector is 2. The vector returned by VDPI and the
initial conditions vector must have the same number of elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in vdpi_1 (line 1)
[t,y] = ode45(@vdpi,[-10 10],[0.1,0.02])
Réponses (1)
Alan Stevens
le 8 Mar 2021
Your function has
function dydt = vdpi1(t,y)
but you really want dy returned, not dydt.
5 commentaires
nune pratyusha
le 8 Mar 2021
nune pratyusha
le 8 Mar 2021
Alan Stevens
le 8 Mar 2021
You have named your function vdpi1, but ode45 is just calling vdpi.
nune pratyusha
le 9 Mar 2021
Modifié(e) : nune pratyusha
le 9 Mar 2021
Walter Roberson
le 9 Mar 2021
Error in usha(line 1)
[t,y] = ode23(@usha,[0 10],0.01);
So file usha line 1 has a call to ode23 specifying @usha as the code to execute, which is the same as the name of the script containing the call to ode23 . If that were going to work at all, it would set up an infinite loop .
You also have function usha somewhere. If it is in the same file, then you have a name conflict with the name of the file, unless function usha is the first function in the file . In particular you cannot have a script named usha that defines a function named usha .
Also symsum() returns a symbolic expression, so v will be symbolic, and so i will be symbolic, and p will be symbolic, and so dydt will be symbolic. But your function must return single or double, never symbolic.
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!