フィルターのクリア

using fzero to solve nonlinear equation

7 ビュー (過去 30 日間)
Jordan Rosales
Jordan Rosales 2021 年 4 月 10 日
コメント済み: Walter Roberson 2021 年 4 月 10 日
I have the nonlinear equation
I need to use fzero to solve for s at different times, t.
In my script, I defined known parameters, created a function handle for the nonlinear equation set to zero, created a loop to calculate concentration at each time point, and within the loop used the fzero function. For my estimation I used 8, as a graph created earlier in the problem seems to approach 0 around 10. As shown in the command window there seems to be missing inputs within my function. However, I have checked thoroughly for missing inputs and even utilized the function outside of fzero and it worked fine. I assume the issue is then with fzero, but I am not sure what it is. Any advice is welcome!

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 4 月 10 日
The function handle you pass to fzero() or to fsolve() must accept only one parameter.
Your s0, vmax, and k are all known constants, and do not need to be passed to the function; when you create the anonymous function, MATLAB will pull them out of the current workspace.
Your code suggests that you are trying to find s that satisfies the expression, but your text description indicates you need to find t ?
  4 件のコメント
Jordan Rosales
Jordan Rosales 2021 年 4 月 10 日
what is 'T' in this solution?
Walter Roberson
Walter Roberson 2021 年 4 月 10 日
T is a dummy variable in an anonymous function. arrayfun() in that form will take each value of t and substitute one value at a time for T into fzero(@(s) km*log(s0/s) + (s0-s) - vmax*T, 8) and collect all of the results.
If you prefer to loop then
tvals = 0:0.1:10;
numt = numel(tvals);
s = zeros(size(tvals));
for tidx = 1 : numt
t = tvals(tidx);
s(tidx) = fzero(@(S) km*log(s0/S) + (s0-S) - vmax*t, 8);
end

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by