Attempted to access c(1); index out of bounds because numel(c)=0. error in pdepe
Show older comments
%%% main file clear all; m=0; global Q phi k muo Swi mug Sor ; Q=10;phi=0.3;k=9*10^-5;muo=0.001;mug=1*10^-6;Swi=0.2;Sor=0.2;
%Define the solution mesh x = linspace(0,1,20); t = linspace(0,0.5,10); %Solve the PDE u = pdepe(m,@eqn1,@initial1,@bc1,x,t); %Plot solution u(1)=u(:,:,1); surf(x,t,u(1)); title('Surface plot of solution.'); xlabel('Distance x'); ylabel('Time t'); %%%%%
function [c,b,s] = eqn1(x,t,u) %EQN1: MATLAB function M-file that specifies %a PDE in time and one space dimension. global Q phi k muo Swi mug Sor ; c = [1;1]; b = (Q/phi)*[(k/muo)*(u(1)^3/(1-Swi*(1-(u(1)+u(2))^5)^4));(k/mug)*(u(2)^3*(2*(1-Sor*(1-u(2)^12)-u(2))/(1-Sor*(1-u(2)^12))^12))]; s = 0;
%%%%%%%%%%%%%% function [pl,ql,pr,qr] = bc1(xl,ul,xr,ur,t) %BC1: MATLAB function M-file that specifies boundary conditions %for a PDE in time and one space dimension. pl = [0;1]; ql = [0;0]; pr = [0.8;0]; qr = [0;0]; end
%%%%%%%%%%%%%%%% function value = initial1(x) %INITIAL1: MATLAB function M-file that specifies the initial condition %for a PDE in time and one space dimension. value = [0;0.8]; end %%%%%%%%%%%% while compiling it's giving the following error.please help !!
Attempted to access c(1); index out of bounds because numel(c)=0.
Error in ==> pdepe at 261 if c(j) == 0
1 Comment
Jan
on 9 Sep 2012
Please, ashish Sachan, learn how to format the code properly. Code formatting has been discussed such frequently in this forum, that I suggest to open any old thread to read the corresponding instructions. --- I admit, this is a little bit exaggerated. Perhaps you need to open 3 or 4 threads. But of course you can search actively for the term "code formatting". Thanks.
Answers (1)
Image Analyst
on 8 Sep 2012
0 votes
Learn how to use the debugger to set a breakpoint at the line in your code that generates the error. Then hover the mouse over the "c" variable. You'll see that it's empty for some reason. I don't know why (one reason it was too hard to read your code because you didn't highlight it and click the "{}Code" icon to properly format it. But once you learn how to use the debugger, you will be able to solve many, many problems like this on your own much much faster than debugging via the Answers forum.
Categories
Find more on Eigenvalue Problems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!