Fzero vs. Solve

5 Ansichten (letzte 30 Tage)
ARSHA MAMOOZADEH
ARSHA MAMOOZADEH am 1 Mai 2019
Kommentiert: Star Strider am 1 Mai 2019
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.
Equation.PNG
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 Kommentare
dpb
dpb am 1 Mai 2019
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
Star Strider am 1 Mai 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by