Trouble with Method of Lines Matlab

In summary, the conversation is about a person struggling with solving an ODE related to radial diffusion. They have attached main files and are getting an error message. Another person responds and points out that r0 is not defined within the function being called. The original person thanks them and asks about the results they are getting, showing that u(r,t) is zero for all values.
  • #1
Ein Krieger
34
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

  • Radial_diffusion.m
    903 bytes · Views: 468
  • dss004.m
    12.8 KB · Views: 462
  • pde1rd.m
    431 bytes · Views: 445
Physics news on Phys.org
  • #2
Hello there,

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

J.
 
  • #3
jfgobin said:
Hello there,

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

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?
 

Related to Trouble with Method of Lines Matlab

1. What is the method of lines in Matlab?

The method of lines is a numerical technique for solving partial differential equations (PDEs) in Matlab. It involves discretizing a PDE into a system of ordinary differential equations (ODEs) using a spatial grid, and then solving the resulting system of ODEs using standard ODE solvers in Matlab.

2. What are the common challenges when using the method of lines in Matlab?

Some common challenges when using the method of lines in Matlab include choosing an appropriate spatial grid and time step size, dealing with boundary conditions, and handling stiff ODEs. It is also important to ensure that the initial conditions and parameters used in the ODE system accurately reflect the PDE being solved.

3. How do I check the accuracy of my method of lines solution in Matlab?

One way to check the accuracy of your method of lines solution in Matlab is to compare it to an analytical solution, if one exists. You can also vary the spatial grid and time step size to see how they affect the solution. Additionally, you can use convergence tests to assess the convergence of your numerical solution.

4. Can the method of lines be used for any type of PDE in Matlab?

The method of lines can be used for many types of PDEs in Matlab, including parabolic, elliptic, and hyperbolic equations. However, it may not be suitable for all PDEs, particularly those with complex geometries or highly nonlinear terms. It is important to carefully consider the applicability of the method of lines to your specific PDE problem.

5. Are there any tips for optimizing the performance of the method of lines in Matlab?

Yes, there are several tips for optimizing the performance of the method of lines in Matlab. These include using vectorization to speed up calculations, choosing an appropriate ODE solver, and utilizing parallel computing if applicable. It is also important to minimize unnecessary calculations and avoid using unnecessary nested loops in your code.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
1
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • Calculus and Beyond Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top