Error, array indices must be positive integers or logical values
11 ビュー (過去 30 日間)
古いコメントを表示
I've read through some other posts but i can't seem to understand why this code gives me the error "array indices must be positive integers or logical values".
clc, clear, clf
f1=@(x,y)x.*exp(x.*y+0.8)+exp(y.^2)-5;
f2=@(x,y)x.^2-y.^2-0.3*exp(x.*y);
x=linspace(-3,3,100); y=linspace(-3,3,100);
[X,Y]=meshgrid(x,y);
Z1=f1(X,Y); Z2=f2(X,Y);
contour(x,y,Z1,[0 0],'green')
hold on
contour(x,y,Z2,[0 0],'r')
grid on
f=@(x)[f1(x,y) f2(x,y)];
D=@(x)-(3*x.*exp(x.*y)+20*y./10);
C=@(x)2*x-(3*y.*exp(x.*y))/10;
B=@(x)2*y.*exp(y.^2)+(x.^2).*exp(x.*y+4/5);
A=@(x)(y.*x+1).*exp(y.*x+4/5);
Df=[A(x) B(x); C(x) D(x)];
x=newton(f(x),Df(x),[1;0.5],1e-5)
0 件のコメント
採用された回答
Jon
2020 年 2 月 14 日
編集済み: Jon
2020 年 2 月 14 日
In your code Df is a 2 by 200 matrix not a function. It therefore does not make sense in the last line of your code to have the expression.
Df(x)
where x is are not integer indices into a matrix.
I think you probably wanted to define an anonymous function
Df =@(x) [A(x) B(x); C(x) D(x)];
Also it is a little strange that you reassign x in the left hand side of your last line of code. You already had a value for x, did you want to overwrite it?
2 件のコメント
Jon
2020 年 2 月 14 日
Glad to hear. Looks like your off to a good start with your MATLAB, just keep at it and it will keep getting more natural
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!