Array indices must be positive integers or logical values.

조회 수: 1 (최근 30일)
y=input('thecomplexvalue of z=');
x=input('therealvalue of z=');
tol=input('the value tolerance tol=');
z=x+1i*y;
funcnew01=z^5+z^3-pi;
funcnew02=diff(funcnew01);
k=0;
if real(z)==0
y=z;
disp('y funcnew01(y) funcnew02(y) k')
disp('........................................')
while abs(funcnew01(y))>tol
y=y-(funcnew01(y)/funcnew02(y));
k=k+1;
end
else
x=z;
disp('x funcnew01(x) funcnew(x) k')
disp('......................................')
while abs(funcnew01(x))>tol
x=x-(funcnew01(x)/funcnew02(x));
k=k+1;
end
end
I get this error in line 20, I'm not shure why I'm trying to make a code for finding the roots of the complex function with the Newton-Raphson method

채택된 답변

the cyclist
the cyclist 2020년 9월 5일
편집: the cyclist 2020년 9월 5일
It seems that you have tried to use this line of code:
funcnew01=z^5+z^3-pi;
to define a general function on z. Then you try to use that "function", e.g. like this:
funcnew01(y)
But that is not what that line of code does. Rather that first line of code, simply defines another variable with the value
z^5+z^3-pi
for whatever the value of z is at the time it is executed.
The specific error you are getting is that your code
funcnew01(x)
is trying to index into a variable (which can only be done with positive integers or logicals).
If you want to define a function, you instead need
funcnew01 = @(z) z^5+z^3-pi;
which can then be called and evaluated the way I believe you intend. See the documentation on anonymous functions for details.
You similarly need to fix funcnew02. I'm not sure what you intend there. A derivative?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by