Question

In: Mechanical Engineering

Write MATLAB scripts to solve problem 5.21 from the textbook (bisection, specific heat) four times: a)...

Write MATLAB scripts to solve problem 5.21 from the textbook (bisection, specific heat) four times:

a) with the bisection method (starting interval [0, 1200])

b) with the false-position method (starting interval [0, 1200])

c) with the Newton-Raphson method (x0 = 0)

d) with the secant method ((x0, x1) = (0, 1))

use percent relative error = 10^-6 as stopping criterion.

5.21-Mechanical engineers, as well as most other engineers, use thermodynamics extensively in their work. The following polynomial can be used to relate the zero-pressure specific heat of dry air cp kJ/(kg K) to temperature (K):

cp = 0.99403 + 1.671 × 10?4T + 9.7215 × 10?8T2 ?9.5838 × 10?11T3 + 1.9520 × 10?14T 4

Develop a plot of cp versus a range of T = 0 to 1200 K, and then determine the temperature that corresponds to a specific heat of 1.1 kJ/(kg K).

Solutions

Expert Solution

Matlab code:txt format

1.bisection.m

%%----Part 1:Bisection Method--------%%
%to apply Bisection Method f(a)*f(b)<0 for interval [a b]
%%----------------Given input------------%%
%%given interval:[a b]= [0 1200]
clear all
clc
a=0;
b=1200;
%%tolerance iput means up to what % of accuracy in y
tor=1e-6;
%%-----Bisection Method iteration---------%%
%%checking weather f(a).f(b)<0 or >=0
if(myfun(a)*myfun(b)>=0)
error('choose another interval for roots finding');
else%if f(a).f(b)<0 then calculate c middle of a and b
c=(a+b)/2;
x(1)=c;
y(1)=myfun(c);
yval=abs(myfun(c));%calculating the value of y at x=c here myfun
%is a function that calulate the value of y
s=0;
while yval>tor
  
s=s+1;
  
if (myfun(a)*myfun(c)<0)
b=c;
else
a=c;
end
c=(a+b)/2;
x(s+1)=c;
y(s+1)=myfun(c);
yval=abs((y(s+1)-y(s)));
end
end
%%---------roots printing--------%%
fprintf('the approximate Temperature is:%.4f',c);

Output:

the approximate Temperature is:544.0842

2.regula.m

%%----Part 2:Regula Falsi Method--------%%
%to apply Regula Falsi Method f(a)*f(b)<0 for interval [a b]
%%----------------Given input------------%%
%%given interval:[a b]= [0 1200]
clear all
clc
a=0;
b=1200;
tor=1e-6;%solution error tolerance

%%-----Secant Method iteration---------%%
if(myfun(a)*myfun(b)>=0||(myfun(b)-myfun(a))==0)
error('choose another interval for roots finding');
else
c=(myfun(b)*a-myfun(a)*b)/(myfun(b)-myfun(a));
x(1)=c;
y(1)=myfun(c);
yval=abs(myfun(c));
ii=0;
while yval>tor
ii=ii+1;
if (myfun(a)*myfun(c)<0)
b=c;
c=(myfun(b)*a-myfun(a)*b)/(myfun(b)-myfun(a));
else
a=c;
c=(myfun(b)*a-myfun(a)*b)/(myfun(b)-myfun(a));
end
x(ii+1)=c;
y(ii+1)=myfun(c);
yval=abs(((y(ii+1)-y(ii))));
end
end
%%--------Print roots----%%
fprintf('the approximate Temperature is:%.4f\n',c);

Output:

the approximate Temperature is:544.0875
3.newton.m

%%----Part 3:Newton Raphson Method--------%%
%no such condition that f(a)*f(b) should be less than or greater zero

%%----------------Given input------------%%
%%given interval [0 1200]
a=0;
%enter the value of accuracy level
accur=1e-6;
  
%---------Newton Raphson Iteration---------%%
if(myfundiff(a)==0)
error('choose another intial guess for roots finding');
else
r=a-(myfun(a))/(myfundiff(a));
yval=abs(myfun(a));
ik=0;
while yval>accur
ik=ik+1;
a=r;
r=a-(myfun(a))/(myfundiff(a));
yval=abs(myfun(a));
end
end
%----------Printing roots------%
fprintf('the approximate Temperature is:%.4f',r);

Output:

the approximate Temperature is:544.0875

4.secant.m

%%----Part 3:Secant Method--------%%
%no such condition that f(a)*f(b) should be less than or greater zero

%%----------------Given input------------%%
%%given interval [0 1200]
clear all
clc
a=0;
b=1200;
tor=1e-6;%solution error tolerance;

%%-----Secant Method iteration---------%%
if((myfun(b)-myfun(a))==0)
error('choose another interval for roots finding');
else
c=(myfun(b)*a-myfun(a)*b)/(myfun(b)-myfun(a));
yval=abs(myfun(c));
ij=0;
while yval>tor
ij=ij+1;
a=b;
b=c;
c=(myfun(b)*a-myfun(a)*b)/(myfun(b)-myfun(a));
yval=abs(myfun(c));
end
end
%%--------Print roots----%%
fprintf('the approximate Temperature is:%.4f\n',c);

Output:

the approximate Temperature is:544.0876

Other two supporting m file for above Matlab code:

1.mufun.m

%here x and y stand for T and Cp respectively
function y=myfun(x)%here function name is myfun

y=-1.1+0.99403+(1.671e-4)*x+(9.7215e-8)*x^2-(9.5838e-11)*x^3+(1.9520e-14)*x^4;

end

2.myfundiff.m

%here x stands for T
function diff_f=myfundiff(x)%here function name is myfundiff

diff_f=(1.671e-4)+2*(9.7215e-8)*x-3*(9.5838e-11)*x^2+4*(1.9520e-14)*x^3;

end

Note: Put all the above Matlab file in same folder then run

Matlab code for Plot of Cp vs T:

plotcp_temp.m

%%------Graph Cp vs T-------%%
x=0:10:1200;
y=0.99403+(1.671e-4).*x+(9.7215e-8).*x.^2-(9.5838e-11).*x.^3+(1.9520e-14).*x.^4;
plot(x,y)
xlabel('T(in K)')
ylabel('Cp(in Kj/kgK)')

Output:

the value of temperature T for which Cp=1.1 Kj/kgK is T=545K (From Graph)


Related Solutions

Write a function to solve the two-dimensional in Matlab, unsteady heat conduction equation with no internal...
Write a function to solve the two-dimensional in Matlab, unsteady heat conduction equation with no internal heat generation on a square domain. The length of each side of the square is 1 m. The function will have the following 4 inputs: npts                     number of grid points in each coordinate direction nt                         number of time steps to take dt                         size of time step (s) alpha                   thermal diffusivity (m2/s) Use the following initial and boundary conditions: Initialize the body to T =...
To find a positive root for , write a MATLAB script file that uses Bisection method....
To find a positive root for , write a MATLAB script file that uses Bisection method. Choose any initial value that is needed. Use absolute relative approximate error to be less than 0.01. Your code should report the number of iteration and the value of x.
Probability and Statistics Write a Matlab simulation to solve problem 2.4.4. 2.4.4. Each problem has a...
Probability and Statistics Write a Matlab simulation to solve problem 2.4.4. 2.4.4. Each problem has a failure probability q, independent of any other component. A successful operation requires: 1. components 1, 2, and 3 all work, or 4 works 2. component 5 or component 6 works. with q = 0.2, simulate the replacement of a component with an ultrareliable component. For each replacement of a regular component, perform 100 trials.
Write two scripts(must be titled “primeSumLoopS” and “primeSumCallS”) in MATLAB that prompts the user to enter...
Write two scripts(must be titled “primeSumLoopS” and “primeSumCallS”) in MATLAB that prompts the user to enter an integer x that 2< x <10000, then the program calculates and displays the sum of the all the prime numbers that are smaller than or equal to x. For example, if x is 11, then the output is 28, which is 2+3+5+7+11. Use two methods: the 1st script uses nested loop and the 2nd script calls another function, primeF.
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and...
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and the standard deviation of a list of numbers. Use the function to calculate the average and the standard deviation of the following list of grades : 80 75 91 60 79 89 65 80 95 50 81
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of...
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of scalar nonlinear equa-tions. Use these programs to compute approximations to real roots of the following equations: exp(x)−3x^2=0, (1) x^3=x^2+x+1, (2) exp(x) =1/(0.1 +x^2), (3) and x= 1 + 0.3 cos(x). (4) Use an error tolerance tol=10^(−12). Display the obtained approximations to the roots of these equations, and compare the number of iterations, starting with the same initial values x0 for bisection and Newton methods,...
Write one a MATLAB function that implements the Bisection method, Newton’s method and Secant Method (all...
Write one a MATLAB function that implements the Bisection method, Newton’s method and Secant Method (all in one function). Your function must have the following signature function output = solve(f,options) % your code here end where the input is • f: the function in f(x) =0. options: is a struct type with the following fields o method: bisection, newton or secant tol: the tolerance for stopping the iterations. maximum_iterations: the maximum number of iterations allowed. initial_guess: that is P_0; if...
Please solve the following problem for MATLAB Write a user-defined function (name it F to C)...
Please solve the following problem for MATLAB Write a user-defined function (name it F to C) that converts temperature in degrees F to temperature in degrees C. Use the function to solve the following problem. The change in the length of an object, ∆L, due to a change in the temperature, ∆T, is given by: ∆L = αL∆T, where a is the coefficient of thermal expansion. Determine the change in the area of a rectangular(4.5 m by 2.25m) aluminum (α=23·10-61/˚C)...
Solve problem (P4.2) from the textbook using the following data instead of the data given in...
Solve problem (P4.2) from the textbook using the following data instead of the data given in the textbook. Solve only requirements under a, b and c. Show your assumptions and consequent calculations on how you catered for the fact that 1997 means first half of the year and 1997.5 means in the second half of the year; without such initial, your solution will not be considered as your own.   (Hint: you may use Excel or any software to conduct linear...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the HTML file that references the JavaScript file. Use prompt to collect names of persons from the user. When the user enters ‘DONE’, your script should stop collecting more names. Then, it should ask the user to specify the following style properties: Border size? 2px, 5px, or 8px. Border Color? blue, red, green, and black. Border style? solid, dotted, dashed, and double. The HTML document...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT