using fzero to solve nonlinear equation
조회 수: 14 (최근 30일)
이전 댓글 표시
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!

댓글 수: 0
답변 (1개)
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
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 Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!