Filter löschen
Filter löschen

using fzero to solve nonlinear equation

7 Ansichten (letzte 30 Tage)
Jordan Rosales
Jordan Rosales am 10 Apr. 2021
Kommentiert: Walter Roberson am 10 Apr. 2021
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!

Antworten (1)

Walter Roberson
Walter Roberson am 10 Apr. 2021
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 Kommentare
Jordan Rosales
Jordan Rosales am 10 Apr. 2021
what is 'T' in this solution?
Walter Roberson
Walter Roberson am 10 Apr. 2021
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Optimization finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by