Effacer les filtres
Effacer les filtres

fsolve not converging at F(x) = 0

2 vues (au cours des 30 derniers jours)
Neilabh Banzal
Neilabh Banzal le 23 Août 2020
Commenté : Neilabh Banzal le 23 Août 2020
Hello,
I have written the attached code for solving the equilibrium of a rigid-link torsional spring model using fsolve.
However, when I evaluate the function values using the output of fsolve, I don't get 0 -
x = Equilibrium_Position
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
-0.4065 0.4065
x =
-0.4065 0.4065
>> k * (x(1) - x(2)) - g * l * sin(x(1)) * (M + m * (n_links - 0.5))
ans =
-8.6695e+04
>> k * (x(2) - x(1)) - g * l * sin(x(2)) * (M + m * 0.5)
ans =
8.6695e+04
I am unable to understant why this is happening. Any help/recommendation is welcome. Thanks!

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Août 2020
>> k * (x(1) - x(2)) - g * l * sin(x(1)) * (M + m * (n_links - 0.5))
You define most of those variables inside your function, and their values disappear when the function returns. You are not at a debug prompt.
We deduce that the visible values of some of the variables (in your base workspace) are not the same as the values in the code.
When I put in a breakpoint and ensure that I am using the values from the file, the calculates values are about 2E-13
  1 commentaire
Neilabh Banzal
Neilabh Banzal le 23 Août 2020
Thanks a lot! Indeed, I have not updated the worksapce variables. Will keep this in mind in the future.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by