fsolve not converging at F(x) = 0

2 visualizzazioni (ultimi 30 giorni)
Neilabh Banzal
Neilabh Banzal il 23 Ago 2020
Commentato: Neilabh Banzal il 23 Ago 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!

Risposta accettata

Walter Roberson
Walter Roberson il 23 Ago 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 Commento
Neilabh Banzal
Neilabh Banzal il 23 Ago 2020
Thanks a lot! Indeed, I have not updated the worksapce variables. Will keep this in mind in the future.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by