Error when solving differential equations

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
Alan Stevens le 8 Mar 2021
Your function has
function dydt = vdpi1(t,y)
but you really want dy returned, not dydt.

5 commentaires

dydt i want just i am giving variable name as dy
i am editted the code but in this also i am getting error. if possible please sort out my error
Alan Stevens
Alan Stevens le 8 Mar 2021
You have named your function vdpi1, but ode45 is just calling vdpi.
nune pratyusha
nune pratyusha le 9 Mar 2021
Modifié(e) : nune pratyusha le 9 Mar 2021
i modified the code
function dydt = usha(t,y)
syms n
a=7.2*10^-6;
Gm=2.5*10^-2
Sp=2.75*10^-5;
yon=6*10^-2;
b=4.7;
son=4.5*10^-1;
B=10^-4;
vm=0:0.5:2.5;
gp=sinh(vm);
A=10^-10;
soff=1.3*10^-2;
beta=500;
yoff=1.3*10^-2
v=symsum((1/n)*sin(2*n*pi*10*t),n,1,100)
i=v.*(y*Gm+(1-y)*a.*exp(b*sqrt(abs(v))))
p=i.*v
dydt = B*sinh(v/son).*exp(-y.^2/yon^2).*exp(p/Sp)
[t,y] = ode23(@usha,[0 10],0.01);
plot(t,y)
my errror is:
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode23 (line 114)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in usha(line 1)
[t,y] = ode23(@usha,[0 10],0.01);
what i have to do
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.

Connectez-vous pour commenter.

Produits

Version

R2020b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by