MATLAB: pdepe boundary function

Why did I get an error like ''Subscript indices must either be real positive integers or logicals. Error in bcfcn (line 7) qr = Ds*J(t,1)'' when I used pdepe matlab solver to solve diffusion equation in spherical coordinate. The Ds is just an constant, but J is actually a vector with respect to time which has both very large positive and negative integers. I cannot change these value to all positive since it is a boundary condition given.
Is that because I need to change the J vector to some function with respect to time?? Actually I have tried to change all J to positive to figure out how does it work, but it doesn't work either.
Thank you very much!

1 Commento

Lu Xia
Lu Xia il 30 Giu 2016
Subscript indices must either be real positive integers or logicals.
Error in bcfcn (line 7) qr = J(t,1)
Error in pdepe/pdeodes (line 337) [pL,qL,pR,qR] = feval(bc,xmesh(1),u(:,1),xmesh(nx),u(:,nx),tnow,varargin{:});
Error in ode15s (line 383) f1 = feval(odeFcn,t+tdel,y,odeArgs{:});
Error in pdepe (line 289) [t,y] = ode15s(@pdeodes,t,y0(:),opts);
Error in CsPDEbysolvers (line 18) sol=pdepe(m,@pdefun,@pdex1ic,@bcfcn,x,t);

Accedi per commentare.

 Risposta accettata

Torsten
Torsten il 1 Lug 2016

0 voti

If "Time" is the vector of time instants corresponding to J, you will have to interpolate J to the time "t" requested by the solver:
Jactual=interp1(Time,J,t);
See the example "ODE with Time-Dependent Terms" under
for a similar problem.
Best wishes
Torsten.

3 Commenti

Lu Xia
Lu Xia il 1 Lug 2016
Thank you very much! I changed the 'qr = interp1(1:60, J(:,1)', t, 'linear', 'extrap');', it really works. But I am a little bit confused that I already set the timespan as t=1:60 which are supposed to be 60 integers. Why will the time "t" requested by the solver become totally different from the timespan I set in the main function, which has time interval smaller than 1?
Torsten
Torsten il 1 Lug 2016
The timespan you set before calling pdepe are the times where you request outputs of the solution.
The time steps the solver uses internally and the times when the solver asks you to supply pde-function + boundary conditions are set to ensure your prescribed error tolerance. They have absolutely nothing to do with your tspan-vector (except for start- and endpoint of the integration).
Best wishes
Torsten.
Lu Xia
Lu Xia il 1 Lug 2016
It is very clear. Thank you very much, Torsten!
Lu

Accedi per commentare.

Più risposte (0)

Richiesto:

il 30 Giu 2016

Commentato:

il 1 Lug 2016

Community Treasure Hunt

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

Start Hunting!

Translated by