フィルターのクリア

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.
  1 件のコメント
MaxPr
MaxPr 2017 年 3 月 1 日
Oh!! Thanks!! I'm so stupid. It should be
for j=2:N-1
I knew it had to be a small thing, but I couldn't see it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeometry and Mesh についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by