Finding Roots between a Differential and Piecewise Equation
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mike
el 25 de En. de 2023
Comentada: Vignesh Ramakrishnan
el 5 de Mzo. de 2024
Hey all!
I am currently working on a project where I have to plot the roots between two of my functions with the help of fzero. I understand that I need to create a third function h(x) where h(x) = g(x) - f(x). But one of the functions is a piecewise equation. Therefore, I am not 100% sure how to find the roots between the two.
This is my piecewise function:
xp1 =@(t) ((-(8*2)/(2^2+1))*cos(t))+((8/(2^2+1))*sin(t));
x1 =@(t) (((8*2)/(2^2+1))+6)*exp(-t/2) + xp1(t);
x2 =@(t) x1(pi)*exp((pi-t)/a);
This is my other function:
fun1 =@(t) (((4+((8*2)/(2^2+1)))*exp(-2*t))+((8/(2^2+1))*(sin(t)-2*cos(t))))
I am able to plot both of them but I dont understand how to find the roots between these two. Any help would be appreciated.
1 comentario
Respuesta aceptada
Matt J
el 26 de En. de 2023
Editada: Matt J
el 26 de En. de 2023
a=1;
[t_root,fval]=fzero(@(t)rootFcn(t,a), pi)
function out=rootFcn(t,a)
xp1 =@(t) ((-(8*2)/(2^2+1))*cos(t))+((8/(2^2+1))*sin(t));
x1 =@(t) (((8*2)/(2^2+1))+6)*exp(-t/2) + xp1(t);
x2 =@(t) x1(pi)*exp((pi-t)/a);
fun1 =@(t) (((4+((8*2)/(2^2+1)))*exp(-2*t))+((8/(2^2+1))*(sin(t)-2*cos(t))));
out=fun1(t);
if t<=pi
out=out-x1(t);
else
out=out-x2(t);
end
end
5 comentarios
Walter Roberson
el 27 de En. de 2023
The algorithm, created by T. Dekker, uses a combination of bisection, secant, and inverse quadratic interpolation methods
I would note that all three of those methods involve interpolation mathematics that is not valid if the derivatives are not continuous.
Vignesh Ramakrishnan
el 5 de Mzo. de 2024
Additional query: In this question, the solutions of the differential equations are considered. In case we were to use the numerical result obtained from an S-function code for the differential equations, would calling that within the rootFcn() work?
Más respuestas (0)
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!