Filter löschen
Filter löschen

fsolve not converging at F(x) = 0

2 Ansichten (letzte 30 Tage)
Neilabh Banzal
Neilabh Banzal am 23 Aug. 2020
Kommentiert: Neilabh Banzal am 23 Aug. 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!

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by