fsolve Finite difference - Problem: "indices must either be real positive integers or logicals"

1 次查看(过去 30 天)
Hello!
So I'm fairly new to matlab and I seem to run into an error I do not unterstand.
"Subscript indices must either be real positive integers or logicals."
Maybe somebody can spot my error easily?
close all;
clear all;
clc;
eta0=0;
etaInf=9;
deltaEta=0.1; %stepsize eta
N=(etaInf-eta0)/deltaEta+1; %number of nodes +1; later + number of nodes for the belt & the film ;
x0=0;
xInf=1;
deltaX=0.01; %stepsize x
M=(xInf-x0)/deltaX+1; %number of nodes x
anfangswert=horzcat(zeros(M,N),zeros(M,N),zeros(M,N)); %starting values, just zeros for now
%%Aufruf des Solvers
options=optimset('FinDiffType','central','MaxIter',10000);
Sol = fsolve(@(x)Keller_2D_Diskr_c(x(1:M,1:N),x(1:M,N+1:2*N),...
x(1:M,2*N+1:3*N),N,deltaEta,M,deltaX),anfangswert,options);
And the function:
function fval = Keller_2D_Diskr_c(f,g,H,N,deltaEta,M,deltaX)
% initialising space
fval1=zeros(M,N);fval2=zeros(M,N);fval3=zeros(M,N);
% Define functions of the Form F(X)=0
for i=1:M-1
for j=1:N-1
fval1(i,j)=((f(i,j)-f(i,j-1))/deltaEta)-g(i,j);
fval2(i,j)=((g(i,j)-g(i,j-1))/deltaEta)-H(i,j);
fval3(i,j)=((H(i,j)-H(i,j-1))/deltaEta)+f(i,j)*H(i,j)+...
2*x(i,j)*(H(i,j)*((f(i,j)+f(i,j-1)-f(i-1,j)-f(i-1,j-1))...
/2*deltaX)-g(i,j)*((g(i,j)+g(i,j-1)-g(i-1,j)-g(i-1,j-1))...
/2*deltaX));
end
end
%BC's
fval(:,1)=[-f(:,1);1-g(:,1);fval2(:,1)]; %Boundary values at eta=0
for i=2:N-1
fval(:,j)=[fval1(:,j-1);fval2(:,j);fval3(:,i-j)];
end
fval(:,N)=[fval1(:,N-1);-g(:,N);fval3(:,N-1)]; %Boundary values at eta=9
  2 个评论
MaxPr
MaxPr 2017-3-1
编辑:MaxPr 2017-3-1
@Thorsten Hmmm... Not sure what you mean. In the documentation it says:
Nonlinear system solver
Solves a problem specified by
F(x) = 0
for x, where F(x) is a function that returns a vector value.
x is a vector or a matrix; see Matrix Arguments.
Am I on the wrong path here?

请先登录,再进行评论。

采纳的回答

David Goodmanson
David Goodmanson 2017-3-1
Hi Max, You did not mention where in the code the error occurred, but certainly you will get such an error with
for j=1:N-1
fval1(i,j)=((f(i,j)-f(i,j-1))/deltaEta)-g(i,j); % etc.
when j=1, since the index j-1 is zero.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Partial Differential Equation Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by