Effacer les filtres
Effacer les filtres

Is there a way to pass a function handle as an argument for fsolve command?

1 vue (au cours des 30 derniers jours)
Tarek Hajj Shehadi
Tarek Hajj Shehadi le 18 Oct 2022
Modifié(e) : Matt J le 18 Oct 2022
I am trying to extract the fixed (equilibrium) point from a system of two ODEs. First, I constructed the function handle that holds both ODEs
F = @(t) [y(2); (R*omega^2/l)*cos(y(1) - omega*t) - (g/l)*sin(y(1))];
where R=0.5; omega = 0.25; l=1; and g=9.81;. As for omega, it is a function of theta and I managed to extract it as a vector by using ode45. I thought of using fsolve for achieving my main purpose of finding fixed points:
ye = fsolve(@F,[pi/4,pi/4]);
However, this returns an error that F is unrecognized function or variable. This leads me to think that fsolve does not accept function handles. Therefore, I hope there is a way to find fixed points either by using fsolve or via another way. Any help is appreciated.

Réponses (1)

Matt J
Matt J le 18 Oct 2022
Modifié(e) : Matt J le 18 Oct 2022
F is already a function handle, so the call should be something like,
F = @(y) [y(2); (R*omega^2/l)*cos(y(1) - omega*t) - (g/l)*sin(y(1))];
ye = fsolve(F,[pi/4,pi/4]);
However, it is pretty clear that for F(y)=0 that y(2)=0, so really you could have just solved for y(1) using,
f=@(y1) (R*omega^2/l)*cos(y(1) - omega*t) - (g/l)*sin(y1);
y1=fzero(f,pi/4);

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by