Operands Not Scalar ?

[EDIT: 20110609 12:41 CDT - reformat - WDR]
function[x0]=Newton_Iteration(delta,epsilon,maxiter)
x0=5;
for iter=1:1:maxiter
x1=x0-(f(x0)/df(x0));
error=abs(x1-x0);
relerror=2*error/(abs(x1) + delta);
x0=x1;
f_final=f(x0);
if ((error<delta) || (relerror<delta) || (abs(f_final)<epsilon))
break
end
end
ERROR
Operands to the || and && operators must be convertible to logical scalar values.
Error in ==> Newton_Iteration at 17
if ((error<delta) || (relerror<delta) || (abs(f_final)<epsilon))
Error in ==> RF_Model at 187
T_e=Newton_Iteration(1e-10,1e-10,50);
What might be the problem...I am gettin this error once i change the / to ./ in a previous statement which was showing mldivider error...
pls help me out

1 件のコメント

Sean de Wolski
Sean de Wolski 2011 年 6 月 9 日
what is epsilon
size(delta)
size(error)
size(relerror)
size(f_final)
?
Also:
DON'T name your variable 'error' as this is a very useful builtin MATLAB function.

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

 採用された回答

Jan
Jan 2011 年 6 月 9 日

1 投票

This is no valid Matlab syntax:
if ((error<delta) (relerror<delta) (abs(f_final)<epsilon))
I guess, you want something like this:
if (all(error_value < delta) && ...
all(relerror < delta) && ...
all(abs(f_final) < epsilon))
break;
end
I've renamed your variable "error" to something, which does not equal the name of a toolbox function.

3 件のコメント

Gowtham
Gowtham 2011 年 6 月 9 日
No actually it was supposed to be
if ((error_value<delta)|| (relerror<delta) ||(abs(f_final)<epsilon))
is it right now ?
Sean de Wolski
Sean de Wolski 2011 年 6 月 9 日
assuming all of those values are scalars.
Gowtham
Gowtham 2011 年 6 月 9 日
hey thanks ..i got the working code...

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 6 月 9 日

0 投票

You would encounter this problem if f(x0) or df(x0) return a non-scalar, which is something we cannot determine by looking at the code you show.

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

2011 年 6 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by