Fzero vs. Solve
5 次查看(过去 30 天)
显示 更早的评论
Hello, I am trying to solve for the grid covergence index of a simulation using the following equation. All values are known in the equation except for P.

I am solving for P in this equation, and I was wondering if fzero or using solve would be more accurate?
Here is my code for both of my versions
Function = @(P) ((abs(log(abs(F32/F21)))+(log(((r12^P)-(1*sign(F32/F21)))/((r23^P)-(1*sign(F32/F21))))))/(log(r12)))-P;
solP=fzero(Function,2);
syms P
eqn = (abs(log(abs(F32/F21))+(log(((r12.^P)-(1*sign(F32/F21)))/((r23.^P)-(1*sign(F32/F21)))))))/(log(r12))-P == 0;
solP=solve(eqn,P);
Using fzero is significantly quicker by a few minutes as I have to solve this equation for 100 cases. How to these two work, and which would be better for my application?
Thank you
2 个评论
dpb
2019-5-1
Well, what's to argue against speedier? When you don't have need for symbols anyway?
You didn't provide data with which to compute the result but what does
Function(solP)
return? Is it not close enough to zero for your application? Is it significantly (or at least enough different than the solution form solve that your subsequent results will be markedly different using either?
Star Strider
2019-5-1
If you have an idea of what the range of values of ‘P’ should be, first plot it to see how it behaves, specifically looking for multiple roots. That will help guide your choice of solvers.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!