Trouble with Method of Lines Matlab

  • Context: MATLAB 
  • Thread starter Thread starter Ein Krieger
  • Start date Start date
  • Tags Tags
    Lines Matlab Method
Click For Summary
SUMMARY

The discussion centers on troubleshooting a MATLAB implementation of the radial diffusion equation represented by the ODE: du/dt=D*(d^2/dr^2+2/r*du/dr). The user encounters an "Undefined function or variable 'r0'" error due to 'r0' not being defined within the function pde1rd, which is critical for the execution of the dss004 function. Additionally, the output shows that u(r,t) is consistently zero, indicating potential issues with the initial conditions or the setup of the ODE solver, ode15s.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax.
  • Understanding of ordinary differential equations (ODEs) and their numerical solutions.
  • Knowledge of the Method of Lines technique for solving PDEs.
  • Experience with MATLAB's ODE solvers, specifically ode15s.
NEXT STEPS
  • Define the variable 'r0' within the pde1rd function to resolve the undefined variable error.
  • Investigate the initial conditions set for the ODE to understand why u(r,t) is returning zero.
  • Review the implementation of the dss004 function to ensure it correctly processes the inputs and computes the expected outputs.
  • Explore MATLAB's documentation on the Method of Lines for additional insights on solving PDEs.
USEFUL FOR

This discussion is beneficial for MATLAB developers, researchers working with numerical methods for PDEs, and anyone troubleshooting ODE implementations in MATLAB.

Ein Krieger
Messages
32
Reaction score
0
Hello, guys

I am struggling with solving the following ODE related to radial diffusion equation:

du/dt=D*(d^2/dr^2+2/r*du/dr)

For easiness I have attached the main m.file with general commands in Radial_diffusion.m
pde1d.m contains function to be solved by ODE, and dss004.m contains routines for differential solving.

I am getting the following commands:

Undefined function or variable 'r0'.

Error in pde1rd (line 10)
ur=dss004(0.0,r0,nr,u);

Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode15s (line 149)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in Radial_diffusion (line 30)
[t,u]=ode15s(@pde1rd,tout,u0,options);

Can you please indicate where I did wrong?
 

Attachments

Physics news on Phys.org
Hello there,

Your function pde1rd(t,u) calls dss04(0.0,r0,nr,u). While u is an argument of the first function and nr is defined as a global variable, r0 is neither and is not defined within pde1rd.

J.
 
jfgobin said:
Hello there,

Your function pde1rd(t,u) calls dss04(0.0,r0,nr,u). While u is an argument of the first function and nr is defined as a global variable, r0 is neither and is not defined within pde1rd.

J.

Thanks. I've got it.

But the values of u(r,t) from the following command

fprintf('\n nr=%2d r0=%4.2f \n', nr,r0);
for it=1:nout
fprintf('\n t=%4.2f\n', t(it));
for i=1:2:nr
fprintf('r=%4.1f u(r,t)=%8.5f\n', r(i), u(it));
end

end
fprintf('\n ncall=%5d\n', ncall)
show that for each value of r and t u(r,t) is zero. Why is it showing such results?
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K