Error when solving differential equations

2 views (last 30 days)
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])

Answers (1)

Alan Stevens
Alan Stevens on 8 Mar 2021
Your function has
function dydt = vdpi1(t,y)
but you really want dy returned, not dydt.
  5 Comments
nune pratyusha
nune pratyusha on 9 Mar 2021
Edited: nune pratyusha on 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
Walter Roberson
Walter Roberson on 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.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!