2. Develop a fully commented bisection function. Within your function, ensure th
ID: 3730383 • Letter: 2
Question
2. Develop a fully commented bisection function. Within your function, ensure that you are passing in an anonymous function. 3. Solve the roots problems to find all the roots between -1 and 3 for the following equation: f= sin(x')+x2-2x-009 4. Engineers use thermodynamics in their work. The following equation relates the zero- pressure specific heat of dry air Cp [kJ/(kg K)1 to temperature [K: Cp =0.99403+1.67 1x10-4T +9.721 5x10-8T2-95838x 10-1 1T3 +1·9320x10-14T4 Make a plot of Cp versus temperature from T = 0 to 1300K. Then, find the temperature that corresponds to a cp of 1.1 kJ/(kg K)Explanation / Answer
Answer 2) The method of bisection is frequently used in numerical calculus to find the roots (zeroes) of a function.
The general algorithm is given below, before going into the actual matlab code:
1) Input function f(x) and interval[a,b]
2) For i = 1 to 100, repeat steps 3-11
3) x = (a+b)/2
4) if f(x) == 0 then
5) display x
6) exit loop
7) else if f(a).f(x) < 0 then
8) b = x
9) else
10) a = x
11) End if
12) End loop
Code:
--------
function zero = bisect(fun, a, b)
% fun is an anonymous function, and we have to find a root in the interval [a,b]
% Carrying out the bisection process 100 times
for i = 1:100
x = (a+b)/2
if f(x) == 0 %Check if x is a root
zero = x
% When f(a) and f(x) are opposite it sign, their product is negative
elseif f(a).f(x) < 0 %Trying to check which side of the midpoint(x) the root lies on
b = x % Take only the lower half of the interval
else
a = x % Take the upper half
end % End of if construct
end % End of loop
Answer 3)
f = @(x) sin(x^2) + x^2 - 2x - 0.09
step = 0.1
for i = -1.05:3.05:0.1
if f(i)*f(i+step) < 0
root = bisect(f, i, i+step) % Calling the function defined earlier
disp root
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.