All solutions are NaN in my Method of lines code. Please help.
조회 수: 2 (최근 30일)
이전 댓글 표시
Dear all,
I am trying to implement Method of lines (MOL) to solve my transient PDE. My solutions are all NaN except for the initial values.
'Index exceeds matrix dimensions.
Error in myFP (line 18)
dPdt(i)=((2*alpha^2.*x(i).*(1+h/2))+(h/2)*(2.*alpha.^2+beta)+(alpha.^2*x(i).^2)).*(y(i+1)/h^2)...
Error in solveFPE>@(t,y)myFP(t,y)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in solveFPE (line 15)
[t,y]=ode45(@(t,y) myFP(t,y),tspan,y0);'
%% function defining the diff equation
function fval = myFP(~,y,x)
N=10; %number of intervals
P(1)=0;
P(2:N)=y;
P(N+1)=0;
h=0.1;
%paramters
alpha=0.25;
beta=0.75;
x=linspace(0,20,20);
%define dP/dt
dPdt=zeros(N+1,1);
for i=2:N
dPdt(i)=(a^2*x(i).^(2)+2*a^(2)*x(i)+a^(2)*h+a^2*x(i)+b*h/2)*P(i+1)/h^(2)...
-(a^2*x(i).^(2)+2*a^(2)*x(i))*P(i)/h^(2)...
+(a^2*x(i).^(2)+2*a^(2)*x(i)-a^(2)*h-a^2*x(i)-b*h/2)*P(i-1)/h^(2);
end
fval=dPdt(2:N);
%Initial conditions
N=10;
P0(1:N+1,1)=1;
y0=P0(2:N);
tspan=linspace(0,20,20);
%solving the equation
[t,y]=ode45(@(t,y) myFP(t,y),tspan,y0);
plot(t,y)
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!