This must be done in MATLAB
(1)We begin with creating the following functions in separate files: f.m, df.m, g.m, dg.m.
For example, the functions f and g will be, respectively:
function y=f(x) y=atan(x)+x-1; end
function y=g(x) y=x.^3-x-1; end
The functions df and dg are the functions of the derivatives of f and g, and they need to be created in a similar way. Create df and dg functions?
**Next, we will graph each function on the interval [-4, 4] in
order to choose an initial approximation 0x. The initial value 0x
has to be chosen close to the x-intercept of the function which we
are approximating. Below is the code that will allow you to plot
the function fun in 2-D in order to choose 0x. The function fun
here is a function handle. First, we assign:
fun=@f; and, then, we run the code given below:
x=linspace(-4,4); y=fun(x); plot(x,y); it outputs
the graph of f(x) on the interval [-4, 4].Then, we assign
fun=@g;
and run the code given above one more time to graph the function
g.
Both graphs have to be present in your Live Script
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
clc
clear all
close all
format long;
fun=@f;
x=linspace(-4,4);
y=fun(x);
plot(x,y);
title('Plot of f(x)');
figure;
fun=@g;
x=linspace(-4,4);
y=fun(x);
plot(x,y);
title('Plot of g(x)');
function y=f(x)
y=atan(x)+x-1;
end
function y=df(x)
y=1./(x.^2 + 1) + 1;
end
function y=g(x)
y=x.^3-x-1;
end
function y=dg(x)
y=3*x.^2-1;
end
Kindly revert for any queries
Thanks.
Get Answers For Free
Most questions answered within 1 hours.