clf
function main()
global R t CR
R = 1;
CR = 0;
tend = 0.5; %seconds
%symmetry (spherical)
m = 2;
%evaluate at the following
r = linspace(0, R, 200);
t = linspace(0, tend, 10);
%Calling a routine to solve the PDE
C = pdepe(m, @pdex1pde, @pdex1ic, @pdex1bc, r, t);
C_ratio = C(:, :, 1);
%Plotting the results
figure, plot(r,C_ratio(0.001,:,1), r,C_ratio(0.01,:,1), r,C_ratio(0.0574,:,1), r,C_ratio(0.1,:,1), r,C_ratio(0.2,:,1), r,C_ratio(0.4,:,1))
xlabel('r/R (dimensionless)')
ylabel('C/CR (dimensionless)')
end
function[c,f,s] = pdex1pde(r, t, C, DCDr)
c = 1;
f = [(D * DCDr); 1];
s = [(D * 2/r); 1];
end
function C = pdex1ic(r)
C = 0;
end
function [p1, q1, pr, qr] = pdex1bc(r1, Cl, rr, Cr, t)
p1 = 0;
q1 = 1;
pr = Cr;
qr = 0;
end

4 Comments

Probably because when you call main(), this is throwing an error:
C_ratio(0.001,:,1)
When you call main(), does an error message appear?
No. It gives me a redline error under main, but when I run the code it pulls up a blank graph window.
I updated my answer after seeing your screen shot. Start my removing clf in line 1

Sign in to comment.

 Accepted Answer

Adam Danz
Adam Danz on 29 Apr 2019
Edited: Adam Danz on 29 Apr 2019
Here's what I think is happening.
  1. Remove clf at line 1 of your code. You can't put that before the function definition.
  2. clf at line 1 of your code is producing an empty figure (no axes). Execution stops there due to error at the next line.
  3. if you put the cursor over the red-underlined 'main()' text in the editor, and then press ctrl+m, you'll see why it's underlined. "Unable to define local function.....".
  4. Even if these errors were corrected, you'll get an error within the pdex1pde() function becuase the variable 'D' is not defined.
There may be more errors but now you have a starting point.

4 Comments

Thank you! Would it help if D were defined as a global D? It is a constant diffusion coefficient with no given value.
Adam Danz
Adam Danz on 30 Apr 2019
Edited: Adam Danz on 30 Apr 2019
Global variables are almost always a bad idea. Either pass the value of D into the nested functions as additional inputs or make it a local variable within the nested functions. Either way, D must be define or your code will break.
Thank you for your help!
Sure thing. Feel free to come back and address any related questions or problems.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!