Problem with PDE resolution

1 Ansicht (letzte 30 Tage)
pierantonio lo greco
pierantonio lo greco am 8 Aug. 2020
I get this error message when running my script PDEsol.m
>> PDEsol
Error using /
Matrix dimensions must agree.
Error in pdefun (line 13)
s = [dudx(2)-alpha*u(1)*u(2)*(1/(1-(u(1)/c)*(dudx(2))^(-1)));0];
Error in pdepe (line 246)
[c,f,s] = feval(pde,xi(1),t(1),U,Ux,varargin{:});
Error in PDEsol (line 10)
sol = pdepe(m,@pdefun,@pdeic,@pdebc,x,t)
This is myscript PDEsol.m :
%%
%select spatial and temporal mesh
%x = [0 0.005 0.01 0.05 0.1 0.2 0.5 0.7 0.9 0.95 0.99 0.995 1];
%t = [0 0.005 0.01 0.05 0.1 0.5 1 1.5 2];
x=[0:0.05:1];
t=[0:0.05:0.717];
%%
%solve PDEs system
m = 0;
sol = pdepe(m,@pdefun,@pdeic,@pdebc,x,t);
%%
%extract PDEs solutions
u1 = sol(:,:,1);
u2 = sol(:,:,1);
%%
%pressure oscillation's plot
surf(x,t,u2)
title('Pressure oscillations [Pa]')
xlabel('Distance x [m]')
ylabel('Time t [s]')
Below are the function call by PDEsol.m :
%PDEs system
function [c,f,s] = pdefun(x,t,u,dudx)
%
epsilon=1;
b=1;
c=200;
rho=1.22;
beta=b/(2*(c^3)*rho);
alpha=epsilon/(rho*(c^3));
%
c = [beta*((1/(1-(u(1)/c)*(dudx(2))^(-1)))+u(1)/(c*(1-(u(1)/c)*(dudx(2))^(-1))^2));1];
f = [0;0];
s = [dudx(2)-alpha*u(1)*u(2)*(1/(1-(u(1)/c)*(dudx(2))^(-1)));0];
end
%
%
%initial condition
function u0 = pdeic(x)
u0 = [sin(x);sin(x)];
end
%
%
%boundary condition
function [pl,ql,pr,qr] = pdebc(xl,ul,xr,ur,t)
pl = [ul(1); ul(2)];
ql = [0; 0];
pr = [ur(1)-0.9; ur(2)-0.9];
qr = [0; 0];
end

Akzeptierte Antwort

Uday Pradhan
Uday Pradhan am 12 Aug. 2020
Hi,
This error is produced because in the function “pdefun, you have defined the variable “c” twice. In the first declaration “c” has a scalar value of 200. However,
c = [beta*((1/(1-(u(1)/c)*(dudx(2))^(-1)))+u(1)/(c*(1-(u(1)/c)*(dudx(2))^(-1))^2));1];
changes “c” into a 2 by 1 column vector. Hence, the later line
s = [dudx(2)-alpha*u(1)*u(2)*(1/(1-(u(1)/c)*(dudx(2))^(-1)));0];
causes a dimension mismatch error because “c” is no longer 200. To avoid this, choose a different name for the scalar value (200) or calculate the expression
Val = 1/(1-(u(1)/c)*(dudx(2))^(-1);
before using it to calculate “s” in "pdefun".

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by