Finding Roots between a Differential and Piecewise Equation
6 views (last 30 days)
Show older comments
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 Comment
Accepted Answer
Matt J
on 26 Jan 2023
Edited: Matt J
on 26 Jan 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 Comments
Walter Roberson
on 27 Jan 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
on 5 Mar 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?
More Answers (0)
See Also
Categories
Find more on Polynomials in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!