フィルターのクリア

code on finding the roots using simple bisection method

2 ビュー (過去 30 日間)
B
B 2015 年 5 月 7 日
コメント済み: Geoff Hayes 2015 年 5 月 7 日
what's wrong in the following code:
function s=bisectionpart(s);
xl=5;
xu=100;
xr=xl;
while(1)
xrold=xr;
xr=(xl+xu)/2;
error=abs((xr-xrold)/xr)*100;
if error<0.1
break,
end;
test=fs(xl)*fs(xr);
if test<0;
xu=xr;
else,
xl=xr;
end
end
s=xr;
plot(t,s);
end
function f=fs(s);
s0=10;
vm=0.5;
ks=2;
t=0:50;
f=s0-(vm*t)+ks*log(s0/s)-s;
end
  1 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 5 月 7 日
B - try formatting your above code that it is readable by others, or attach the code to your question using the paperclip button.
A couple of comments: why is s an input parameter to your bisectionpart function. How is it used, and what would it be when you call this function? Also, don't use error as the name of a variable as this is also the name of a built-in MATLAB function.
When I try to run the bisectionpart function, I get an error at line 17
Error using *
Inner matrix dimensions must agree.
Error in bisectionpart (line 17)
test=fs(xl)*fs(xr);
This is because the result returned from fs is an array of 51 elements. Is this expected? What is the purpose of fs i.e. what does it represent or model?

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by