Find zeros for the solution of an ode45 multiple variables set of second order equations
1 view (last 30 days)
Show older comments
Hubert Coppieters 't Wallant
on 15 Oct 2020
Edited: Ameer Hamza
on 15 Oct 2020
I have this function and I would like to calculate when it's height hits zero (or close enough) for further calculations, but I can't manage to select its variables, since by using ode45 I also selected the derivatives as being variables (this or any other mistake)
how should I find it's crossing point with z == 0?
here is my function:
t_interval = [0,1];
[t,y] = ode45(@afst, t_interval, b_waarden);
function dxy = afst(t,Y)
%parameters
rho = 1.239;
g = 9.81;
Cw = 0.5
A = pi * (0.02)^2
m = 0.025
dxy = [Y(2);
-(1/m) * (rho*A*Cw*0.5) * sqrt((Y(2))^2 + (Y(4))^2) * (Y(6)));
Y(4);
-(1/m) * (rho*A*Cw*0.5) * sqrt((Y(2))^2 + (Y(4))^2 + (Y(6))^2) * (Y(2));
Y(6);
-(1/m) * (rho*A*Cw*0.5) * sqrt((Y(2))^2 + (Y(4))^2 + (Y(6))^2) * Y(4) - g];
end
and this is what I tried to find it's zero, but it never works:
nul = fsolve((y(:,5) == 0),(0; 0; 0))
or
nul = fsolve((y == (:, :, :, :, 0, :), (0; 0; 0; 0; 0; 0)))
please help me
0 Comments
Accepted Answer
Ameer Hamza
on 15 Oct 2020
Edited: Ameer Hamza
on 15 Oct 2020
No, this is not the correct approach to do this in MATLAB. fsolve() only works with functions handle, while you have a numeric vector. Following shows one approach to find the element closest to 0
y5 = y(:,5); % get values from 5th column
[~, min_idx] = min(abs(y5));
min_val = y5(min_idx); % value nearest zero.
min_t = t(min_idx); % time at which the min_val occured
0 Comments
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!