Find zeros for the solution of an ode45 multiple variables set of second order equations
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Ameer Hamza
2020년 10월 15일
편집: Ameer Hamza
2020년 10월 15일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!