Question

In: Computer Science

MATLAB Coding. Please answer with respected Matlab code format HW 2_5 Determine the two roots of...

MATLAB Coding. Please answer with respected Matlab code format

HW 2_5

Determine the two roots of f(x) = 2x cos(2x) − (x − 2)^2 , using falsepos.p, accurate to 3 sig figs. Plot these points on the graph with a star marker.

Solutions

Expert Solution

`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
f = @(x) 2*x.*cos(2*x)-(x-2).^2;
hold on;
fplot(f,[0,4]);
a1=[2,3.2];
a2=[3,4];
for kk=1:2
e=1e-3;
x0=a1(kk);
x1=a2(kk);
i=0;
imax=200;
x2=x1+1;
flag=1;
while (abs(x2-x1)>e)
if(i~=0)
x1=x2;
end
x2=x1-((f(x1)/(f(x1)-f(x0)))*(x1-x0));
x0=x1;
i=i+1;
if(i==200)

disp('the required accuracy is not reached in 100 iterations');
flag=0;
end
end
if(flag==1)
root=x2;
else
root=[];
end
fprintf('x is %.3f\n',root);
plot(root,f(root),'*');
end

Kindly revert for any queries

Thanks.


Related Solutions

PLEASE USE PYTHON CODE 7. determine the two roots of sinx+3cosx-2 =0 that lie in the...
PLEASE USE PYTHON CODE 7. determine the two roots of sinx+3cosx-2 =0 that lie in the interval (-2,2). use the Newton- Raphson method and solve by the secant formula
determine whether the given function is even, odd, or neither. Please write a code in MatLab...
determine whether the given function is even, odd, or neither. Please write a code in MatLab to solve this problem below: 1.f(x) = sin 3x please only use Matlab to solve this problem
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications: Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4. The plot should have: (1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin...
Please post code in format that can be copied. If possible please explain code but not...
Please post code in format that can be copied. If possible please explain code but not necessary. Directions: 1. Create a new project for the lab and copy stat.h, stat.cpp, and teststat.cpp into your workspace. 2. Now review the header file. Make sure you understand the design. Can you explain the difference between what the class represents versus how it plans to accomplish it? 3. Now edit the stat.cpp file. Notice that many of the member functions are missing. For...
Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you...
Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you cannot give correct MATLAB
Answer in MATLAB format. 4. A telephone line hangs between two poles 14 m apart in...
Answer in MATLAB format. 4. A telephone line hangs between two poles 14 m apart in the shape of a catenary y = 20cosh (x/20)-15, where x and y are measured in meters. a. Find the slope of this curve where it meets the right pole. b. Find the angle, θ between the line and the pole.
In java. Determine the value of each of the following expressions. (Format your answer with two...
In java. Determine the value of each of the following expressions. (Format your answer with two decimal places.) a. Math.abs(-4) b. Math.abs(10.8) c. Math.abs(-2.5) d. Math.pow(3.2, 2) e. Math.pow(2.5, 3) f. Math.sqrt(25.0) g. Math.sqrt(6.25) h. Math.pow(3.0, 4.0) / Math.abs(-9) i. Math.floor(28.95) j. Math.ceil(35.2)
**MATLAB Code only Please create a MATLAB script that is a TIC-TAC-TOE game. Please keep it...
**MATLAB Code only Please create a MATLAB script that is a TIC-TAC-TOE game. Please keep it simple, but there is no other rules. Thank you.
please let me know reference of this MATLAB code. please explain this code line by line....
please let me know reference of this MATLAB code. please explain this code line by line. . . N=256; %% sampling number n=linspace(0,1,N); fs=1/(n(2)-n(1)); x=5*(sin((2*pi*10*n))); %% create signal N=length(x); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(211) plot(f,fftshift(abs(fft(x)))); title('|G(f)|');grid; xlabel('frequency'); ylabel('|G(f)|'); %Zero padding xx=[zeros(1,128) x zeros(1,128)]; N=length(xx); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(212) plot(f,fftshift(abs(fft(xx)))); title('|Gz(f)|');grid; xlabel('frequency'); ylabel('|Gz(f)|');
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW...
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials * * 2. Adding polynomials * * 3. Multiplying polynomials. * * 4. Displaying polynomials * * 5. Clearing polynomials. * * 6. Quit. * *********************************** Select the option (1 through 6): 7 You should not be in this class! ************************************* *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT