subscript indices error with function file (bisection method)
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
function result=guess(x)
xleft=x(1,1);
xright=x(1,2);
f(x)= x.^3 - 4.9*x.^2 +6.76*x-2.013
if f(xleft)*f(xright)<0
result= 'guess is valid'
else
result= 'guess is not valid'
end
I enter in x=[0,1] and I want my program to define xleft as 0 and xright as 1 and then multiply f(0) with f(1) and tell me whether the product is <0 or not. Why won't it do this?
Also, if I wanted to enter in a matrix like x=[0,1;1,3;5,0] Then I would do
f= x.^3 - 4.9*x.^2 +6.76*x-2.013
for ii=1:3
xleft=x(ii,1)
xright=x(ii,2)
But this won't work either.
0 件のコメント
回答 (2 件)
Walter Roberson
2018 年 2 月 22 日
f(x)= x.^3 - 4.9*x.^2 +6.76*x-2.013
looks like you are trying to define a formula, not trying to calculate a value based upon specific x. You should probably be using
f = @(x) x.^3 - 4.9*x.^2 +6.76*x-2.013;
0 件のコメント
Nilesh Bhosale
2018 年 4 月 12 日
0 投票
Give simple program of Bisection method
1 件のコメント
Walter Roberson
2018 年 4 月 12 日
That does not appear to be an Answer to this Question?
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!