How to Input a function equation in matlab

12 ビュー (過去 30 日間)
Ivy Shen
Ivy Shen 2018 年 10 月 3 日
編集済み: Stephen23 2018 年 10 月 3 日
Hi, I have an equation as following:
F - hm*(a-b)*log(1+F/(hm*(a-b))) = kt
I am trying to use fzero to solve for F in matlab, but I don't know how to input this equation in matlab first?
  4 件のコメント
Ivy Shen
Ivy Shen 2018 年 10 月 3 日
I am trying to write a function as following:
function F = GreenAmp(Ks,hm,t,a,b)
F - hm*(a-b)*log(1 + F/(hm*(a-b))) = Ks*t;
And I don't know what's the next step. Is there any easier way to do it? Can you specify which documentation I should look at?
Thank you.
Stephen23
Stephen23 2018 年 10 月 3 日
編集済み: Stephen23 2018 年 10 月 3 日
function F = GreenAmp(Ks,hm,t,a,b)
F - hm*(a-b)*log(1 + F/(hm*(a-b))) = Ks*t;
That will not work:
  • variable F is used but undefined. In order to solve for F, F must be one of the input arguments to the function.
  • the LHS of the = sign is not valid for assignment: the LHS should be one variable, which is the value of the function when it is evaluated.
"Can you specify which documentation I should look at?"

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

回答 (1 件)

Stephen23
Stephen23 2018 年 10 月 3 日
編集済み: Stephen23 2018 年 10 月 3 日
>> b = 1;
>> a = 2;
>> hm = 0.5;
>> kt = 0.9;
>> fun = @(F) F - hm*(a-b)*log(1+F/(hm*(a-b)));
>> y = fzero(@(x)fun(x)-kt,0)
y = 1.6230
>> fun(y)
ans = 0.90000
Note that this curve might have multiple solutions, depending on the parameter values: fzero only finds one solution, so you will have to adjust its starting value to find any other solutions. You should always plot the curve and check if the solution is reasonable:
X = -10:0.1:10;
Y = arrayfun(fun,X);
plot(X,Y)
hold on
plot(y,0.9,'*')
  1 件のコメント
KSSV
KSSV 2018 年 10 月 3 日
I have deleted my answer..which was ridiculous.

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

カテゴリ

Help Center および File ExchangeOptimization Toolbox についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by