Hello everyone, I am being asked in a homework question to find the instants a function y(t)=4*exp(-0.3t)sin(3t+0.25) crosses zero (the roots) in the interval 0<t<4. I have developed a code that uses Newton Raphson to find roots for functions. Here is that function:
function Xs=NewtonRoot(Fun,FunDer,Xest,Err,imax)% NewtonRoot: finds the root of Fun=0 near the point Xest using Newton's
% method.
%Fun: Name of a user-defined funtion that calculates Fun for a given x.
% FunDer: Name of a user-defined function that calculates the derivative of
% Fun for a given x.
% Xest: Initial estimate of the solution.
% Err: Maximum error
% imax: Maximum number of iterations
% Output variable
%Xs Solution
for i=1:imax Xi=Xest-Fun(Xest)/FunDer(Xest); if abs((Xi-Xest)/Xest)<Err Xs=Xi; break end Xest=Xi;end if i==imax fprintf('Solution was not obtained in %i iterations.\n',imax) Xs=('No answer');endend
And then I create a function for both y(t) and y'(t). Here is y(t):
function y=problem3fun(x)% This is the function for damping oscillator
y=4*exp(-0.3*x)*(sin((3*x)+0.25));end
and y'(t):
if true function y=problem3funDer(x)y=-exp((3*x/10)*(6*sin((3*x)+0.25))-60*cos((3*x)+0.25)/(5));endfunction y=problem3funDer(x)y=-exp((3*x/10)*(6*sin((3*x)+0.25))-60*cos((3*x)+0.25)/(5));end
So I think what my problem is that I do not know how to display multiple roots. I have a few guesses (Xest) but I can only at this point guess one root and thats it. On the command line:
Tsolution=NewtonRoot(@problem3fun,@problem3funDer,1,0.001,20)
Tsolution =
1.0000
So my question is how can I make my function work to find multiple roots of this y(t).
Best Answer