clear all
close all
%function for which root have to find
fun=@(x) exp(x)-3.*x-1;
x0=-1;x1=3;
maxit=1000;
[root1,iter1]=bisection_method(fun,x0,x1,maxit,10^-5);
fprintf('For error limit 10^-5 number of iteration =%d and
root=%f\n',iter1,root1)
[root2,iter2]=bisection_method(fun,x0,x1,maxit,10^-10);
fprintf('For error limit 10^-10 number of iteration =%d and
root=%f\n',iter2,root2)
g=@(x) log(3*x+1);
[root,iter]=fixed_method(g,1,maxit,10^-10);
fprintf('For error limit 10^-10 with initial guess 1, number of
iteration =%d and root=%f\n',iter,root)
[root,iter]=fixed_method(g,2,maxit,10^-10);
fprintf('For error limit 10^-10 with initial guess 2, number of
iteration =%d and root=%f\n',iter,root)
%Matlab function for Bisection Method
function [root,iter]=bisection_method(fun,x0,x1,maxit,tol)
if fun(x0)<=0
t=x0;
x0=x1;
x1=t;
end
fprintf('\nRoot using Bisection method for f(x)=')
disp(fun)
%f(x1) should be positive
%f(x0) should be negative
k=10; count=0;
while k>tol
count=count+1;
xx(count)=(x0+x1)/2;
mm=double(fun(xx(count)));
if mm>=0
x0=xx(count);
else
x1=xx(count);
end
err(count)=abs(fun(x1));
k=abs(fun(x1));
if count>=maxit
break
end
if count<=5
fprintf('\tAfter %d
iteration root using Bisection method is
%f\n',count,xx(count))
end
end
root=xx(end); iter=count;
end
%Matlab function for Fixed point Method
function [root,iter]=fixed_method(fun,x0,maxit,tol)
k=10; count=0;
fprintf('\nRoot using fixed point method for
f(x)=')
disp(fun)
while k>tol
count=count+1;
xx=fun(x0);
k=abs(xx-x0);
x0=xx;
rr(count)=xx;
%k=abs(fun(xx));
if count <=5
fprintf('\tAfter %d iteration root using fixed point method is
%f\n',count,rr(count))
end
if count>=maxit
break
end
end
root=rr(count);
iter=count;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NEED HELP ESPECIALLY ON C,D,E,F 2. [6pt] We attempt to find all solutions to f(x) =...
I need help with d) please help thank you Question 1 Wave motion appears in all branches of physics. In the lectures we considered the solution of the advection equation, a first-order hyperbolic PDE. Here we consider the solution of the wave equation: c2 where c >0 is constant. , We assume all variables have been non-dimensionalised. (a) Eq. (1) has the general solution (d'Alembert, 1747): u(x,t) F(x -ct) +G(x ct), where F and G are arbitrary functions. Consider the...
I need help creating program for the Test_Bisection pseudocode. I need to find a root for each function f and g and get the output below. Pseudocode Now let's construct pseudocode to carry out this procedure. We shall not try to create a piece of high-quality software with many "bells and whistles,” but we write the pseudocode in the form of a procedure for general use. This allows the reader an opportunity to review how a main program and one...
1. Consider the following function F(x) x 2 where x = [x1 x2]T (d) Write a code to implement conjugate gradient method on this function. In each case, start with an initial guess of [1 1]T and plot both the solution at each iteration and the contour plots of the function on the same plot to show the trajectory towards the solution. Does it matter what the initial guess is? 1. Consider the following function F(x) x 2 where x...
Not in C++, only C code please In class, we have studied the bisection method for finding a root of an equation. Another method for finding a root, Newton's method, usually converges to a solution even faster than the bisection method, if it converges at all. Newton's method starts with an initial guess for a root, xo, and then generates successive approximate roots X1, X2, .... Xj, Xj+1, .... using the iterative formula: f(x;) X;+1 = x; - f'(x;) Where...
Parts e, f, and g only please 2. Let f(x) = -3x + 2 for 0 < x < 1. (a) If we partition the interval (0, 1) into five subintervals of equal length Ar, 0 = xo <12 <2<83 < 14 < 25 < x6 = 1, what is Ar and what are the ri? (b) Sketch a diagram for each of L5 and R5, the left and right enpoint Riemann sums for f(c) using the partition above. (c)...
(1) Use the Bisection method to find solutions accurate to within 10-2 for x3 – 7x2 + 14x – 6 = 0 on the interval [3.2, 4]. Using 4-digit rounding arithmatic. (2) Consider the function f(x) = cos X – X. (a). Approximate a root of f(x) using Fixed- point method accurate to within 10-2 . (b). Approximate a root of f(x) using Newton's method accurate to within 10-2. Find the second Taylor polynomial P2(x) for the function f(x) =...
2. (a) Suppose we have to find the root xof x); that is, we have to solve )0. Fixed-point methods do this by re-writing the equation in the form x·= g(x*) , and then using the iteration scheme : g(x) Show this converges (x-→x. as n→o) provided that K < 1 , for all x in some interval x"-a < x < x*+a ( a > 0 ) about the rootx 6 points] (b) Newton's method has the form of...
algorithm 2.2 Calculus Suppose you want to find zeros of the function f(x)102212 and plan to use the Newton-Raphson scheme. (a) Write down the Newton-Raphson algorithm for this. That is, write down explicitly a formula for computing your (n+1)st guess Tn+1 given your nth guess rn for a root. In other words, deter- mine the recurrence relation resulting from using this particular function f. (b) Modifying Algorithm 2.2 as required, find the values through r7 if you choose an initial...
Could you label and explain how to get each term? Thank you! 3. Find the equation of the tangent line to the graph of f(x)-1+e 0 4 Graph the following function, using information such as intervals of increase and decrease, relative extrema, intervals of upward and downward concavity, and inflection points: g(x) 3x4 +4.x Pro):-I -2 16 3 a7 al 16 min(-1,-1) y " 30+24K: 12x(3x+2) t ip. (oo) 2 3 3. Find the equation of the tangent line to...
5. Let f(x) = ax2 +bx+c, where a > 0. Prove that the secant method for minimization will terminate in exactly one iteration for any initial points Xo, X1, provided that x1 + xo: 6. Consider the sequence {x(k)} given by i. Write down the value of the limit of {x(k)}. ii. Find the order of convergence of {x(k)}. 7. Consider the function f(x) = x4 – 14x3 + 60x2 – 70x in the interval (0, 2). Use the bisection...