fsolve wont take the initial guess
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I'm having a problem solving a NDF using fsolve with an event. There are 2 variables y(1) and y(2) where we need to do an order reduction getting a total of 4 variables to the ODE problem. Objective of the code is to find when will both variables be equal to x_wall. The code is as such
y0 = [pi/8 1 0 0]; %inital guess
t_step = 0.1; %time step
t_interv = [0 10];
x_wall = -0.5; %final position
Y=fzero(@(x) solver(t_step, t_interv, x, x_wall), y0 );
function F= solver(t_step, t_interv,x, x_wall)
l1=1;l2=1;
[t,y] = MY_RK4_event(@My_DoublePendulum, t_step, t_interv, x, x_wall);
X1 = sin(y(1,end))*l1;
X2 = X1+sin(y(2,end))*l2;
F=[X1 X2 0 0]-[x_wall x_wall 0 0]; %final condition
end
I keep getting an error saying that i can only input 2 inputs to the solver, and when inputing 2 inputs the fsolve only send in y0(1) as variable x in the function solver.
Why?
5 commentaires
Stephan
le 7 Déc 2020
Maybe my english language knowledge is to poor, but did you notice that you use fzero:
Y=fzero(@(x) solver(t_step, t_interv, x, x_wall), y0 );
instead of fsolve? Is it that simple?
Réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with Optimization Toolbox 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!