so by doing this problem over and over again i finally got the right answer but
ID: 3873639 • Letter: S
Question
so by doing this problem over and over again i finally got the right answer but could someone write the code that proves this in matlab ?
Question 6 5/ 5 pts We wish to find a solution using an iterative technique. Using a supplied function we wish to achieve a solution that changes less than 0.01% between iterations. Review the relevant sections of the code shown below and determine what is the value of es that we should input the function. function [out] “ iterati ini, in2, e, maalt, tor 1-11100 ea -aba inew-old)/new it ea es,break, end end Corect 0.0001 0.01 0.001Explanation / Answer
The main aim of the question is to find the value of es.
es = 0.01% = 0.01/100= 0.0001
To verify the statement of question,
You can consider the example of newton rapsion methode. When the change in root becomes smaller than es, we stop the program and output value of root.
Matlab code:
function [out] = iterative(in1, in2 ,es,maxIt)
syms a;
func = @(x) (3*(x^3) - 6*(x^2) + 4*x - 8/9); %define the function
x= 2; %initial guess
tmp(1) = in1;
g = matlabFunction(diff(func(a),a)); % derivative of function
h = (func(x))/ (g(x));
i = 1;
while(abs(h) > es & i< maxIt)
h = func(x)/ g(x);
x = x - h; % update value of root
i=i+1;
end
root = x % final value of root
out = root;
end
Sample Output:
>> iterative(2,3,0.0001,100)
root =
0.6668
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.