필터 지우기
필터 지우기

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
Torsten
Torsten 2017년 3월 1일
fsolve works with vector inputs, not with matrix inputs.
Best wishes
Torsten.
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에서 Geometry and Mesh에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by