too many input arguments when using pdepe

Hi, I meet a problem when using pdepe, and I tried many ways but can't solve this. Could you help me with this?
I got errors like 'too many/ not enough argument when using pdepe' when modifying
sol = pdepe(m,@(t,u) wave_ode1(x,t,u,dudx,p),@pdeic2,@pdebc2,x);
my code is below:
Thank you!
clear all
close all
hx = 0.1;%need try 0.01
L = 10;%
x = 0:hx:L;
t = [0:0.1:200];
Da=0.1;
Db=10;
m = 0;
p=[Da;Db];
sol = pdepe(m,@(t,u) wave_ode1(x,t,u,dudx,p),@pdeic2,@pdebc2,x);
u1 = sol(:,:,1);
u2 = sol(:,:,2);
surf(x,t,u1)
title('u_1(x,t)')
xlabel('Distance x')
ylabel('Time t')
surf(x,t,u2)
title('u_2(x,t)')
xlabel('Distance x')
ylabel('Time t')
function [c,f,s] = wave_ode1(x,t,u,dudx,p) % Equation to solve
c = [1; 1];
f = [Da; Db] .* dudx;
y = u(1) - u(2);
F = exp(5.73*y)-exp(-11.47*y);
s = [-F; F];
end
function u0 = pdeic2(x) % Initial Conditions
u0 = [1; 0];
end
function [pl,ql,pr,qr] = pdebc2(xl,ul,xr,ur,t) % Boundary Conditions
pl = [0; ul(2)];
ql = [1; 0];
pr = [ur(1)-1; 0];
qr = [0; 1];
end

 Réponse acceptée

Torsten
Torsten le 25 Mar 2022
sol = pdepe(m,@(x,t,u,dudx) wave_ode1(x,t,u,dudx,p),@pdeic2,@pdebc2,x,t);
function [c,f,s] = wave_ode1(x,t,u,dudx,p) % Equation to solve
c = [1; 1];
f = [p(1); p(2)] .* dudx;
y = u(1) - u(2);
F = exp(5.73*y)-exp(-11.47*y);
s = [-F; F];
end

5 commentaires

ZIYI LIU
ZIYI LIU le 25 Mar 2022
Modifié(e) : ZIYI LIU le 25 Mar 2022
Hi Torson, this works for me! Thank you very very much!
Could you help me with another question please? Also with this code.
The problem is that there is a stimuli in the system which denpends in x and t, for example:
(But the code has errors)
function [c,f,s] = wave_ode1(x,t,u,dudx,p) % Equation to solve
c = [1; 1];
f = [p(1); p(2)] .* dudx;
y = u(1) - u(2);
ss=piecewise((0<= t) & (t <= 20),0.05/2,(20< t) & (t <= 25),0.05/4*(1+cos(pi*(t-20)/(25-20))),0);
ks=piecewise((0<= x) & (x <= 1),ss*(1+cos(pi*x)),1);
F = exp(5.73*y)-exp(-11.47*y)+ks;
s = [-F; F];
end
Torsten
Torsten le 25 Mar 2022
Modifié(e) : Torsten le 25 Mar 2022
if x <= 1
if t <= 20
ss = 0.05/2;
elseif t > 20 && t <= 25
ss = 0.05/4*(1+cos(pi*(t-20)/(25-20)));
else
ss = 0;
end
ks = ss*(1+cos(pi*x));
else
ks = 1.0;
end
Hi Torsten, thank you very much! But I still met an error like ' The function "pdebc" was closed with an 'end', but at least one other function definition was not. All functions in a script must be closed with an 'end'.'. My modified code is below:
function [c,f,s] = wave_ode1(x,t,u,dudx,p) % Equation to solve
Da=p(1);
Db=p(2);
c = [1; 1];
f = [Da; Db] .* dudx;
y = u(1) - u(2);
if t <= 20
ss = 0.05/2;
else if t > 20 && t <= 25
ss = 0.05/4*(1+cos(pi*(t-20)/(25-20)));
else
ss = 0;
end
if x <= 1
ks = ss*(1+cos(pi*x));
else
ks = 1.0;
end
F = exp(5.73*y)-exp(-11.47*y)+ks;
s = [-F; F];
end
elseif
instead of
else if
Hi Torsten, I modified little based on your code and it works for me! Thank you so much!
function [c,f,s] = wave_ode1(x,t,u,dudx,p) % Equation to solve
Da=p(1);
Db=p(2);
c = [1; 1];
f = [Da; Db] .* dudx;
y = u(1) - u(2);
if t <= 20
ss = 0.05/2;
elseif t > 20 && t <= 25
ss = 0.05/4*(1+cos(pi*(t-20)/(25-20)));
else
ss = 0;
end
if x <= 1
ks = ss*(1+cos(pi*x));
else
ks = 1.0;
end
F = exp(5.73*y)-exp(-11.47*y)+ks;
s = [-F; F];
end

Connectez-vous pour commenter.

Plus de réponses (1)

sol = pdepe(m,@(t,u) wave_ode1(x,t,u,dudx,p),@pdeic2,@pdebc2,x);
pdepe needs m, then three function handles, then x mesh, and then time span.
You have m, then three function handles, then x mesh... and no time span.

2 commentaires

ZIYI LIU
ZIYI LIU le 25 Mar 2022
Hi Walter, I add t, but still have error said
'Error in wave (line 14)
sol = pdepe(m,@(t,u) wave11(x,u,dudx,p),@pdeic1,@pdebc1,x,t);'
The pdefun (first function handle) will be passed x, t, u, dudx. Your @(t,u) function handle expects to receive only two parameters.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Linear Algebra 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!

Translated by