All solutions are NaN in my Method of lines code. Please help.

2 ビュー (過去 30 日間)
Vipin  Padinjarath
Vipin Padinjarath 2019 年 5 月 24 日
編集済み: Vipin Padinjarath 2019 年 5 月 24 日
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 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by