Question

Polynomial Curve Fitting Often we can assume that certain thermodynamic properties are constant for the process...

Polynomial Curve Fitting

Often we can assume that certain thermodynamic properties are constant for the process under study. However if there is a large change in temperature during a thermodynamics process this assumption can lead to significant errors; a typical example would be combustion in an engine. In such cases tables can be used. However, tables are awkward to use for computer calculations; therefore, a polynomial equation is often used in computer programs that simulate thermodynamics processes.

As an example of how to apply polynomial equations in a computer program, we will consider the specific heat capacity at constant pressure, cp, of carbon dioxide. The standard value used for CO2 is the value at 300 K:

cp = 0.846 kJ/kg·K

But for large temperature change the following polynomial is used

Cp/R = a1 + a2T + a3T^2 + a4T^3 + a5T^4

where the gas constant for CO2 is R = 0.1889 kJ/kg·J.

The coefficients, ai, depend on the type of gas and the temperature range. For CO2, we have:

ai

300 ≤ T ≤ 1000

1000 < T ≤ 3000

a1

0.24007797e+01

0.44080e+01

a2

0.87850957e-02

0.309817e-02

a3

-0.6607878e-05

-0.123925e-05

a4

0.20021861e-08

0.227413e-09

a5

0.63274039e-15

-0.155259e-13

Programming:

You will write two MATLAB functions and a MATLAB script that will drive a menu:

CO2: Function cp for CO2: There will be one input to this function: a temperature in Kelvin. There will be one output from this function: the cp for CO2 based on the above polynomial at the specified temperature. So the function will accept one value for temperature and return one value for cp. Do not use the element-by-element multiplication for array (.*) instead use the scalar multiplication (*).

CpRange: Function range of cp: There will be three (3) inputs to this function: a minimum temperature, a maximum temperature and temperature increment—these will define an array of temperatures. This function will call CO2 to find each value of cp for the given value of the temperature. The function will return the array of temperatures and specific heat capacities. Since the output is an array, what program structure should you use?

Script for the menu: This script will run the menu. When the script is run the user is give a choice of 3 items:

Cp for a given temperature

A plot of Cp vs. T.

Quit

The menu should run on an infinite loop and only terminate when item (3) is selected. If item (1) is select, the user will be prompted to enter a temperature and this will be sent to CO2; then T and cp will be displayed with proper units in the MATLAB Command Window. If item (2) is selected the user will be prompted to enter a minimum and a maximum temperature and a temperature increment; this data will be sent to CpRange and the returned data will be used to produce a plot. You can call MATLAB’s plot function from the menu. Since this is a menu, this is a selection structure. For a menu selection structure it is usually most effective to use the switch/case structure.

Make sure you check the temperature data entered at the menu to ensure it is in the proper range. If the value(s) entered is outside of the range of validity (as specified in the table above), the user should be sent a warning message and the menu should run from the beginning again.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

code:

function cp=CO2(t)
R=.1889;
if t>=300 && t<=1000
cp=0.24007797e+01+0.87850957e-02*t-0.6607878e-05*t^2+0.20021861e-08*t^3+0.63274039e-15*t^4;
elseif t>1000 && t<=3000
cp=0.44080e+1+0.309817e-02*t-0.123925e-05^t^2+0.227413e-09*t^3-0.155259e-13+t^3;
end
cp=cp*R;
end

%%%%%%%%%%%%%%%%%%function CpRange%%%%%%%%%%%%%%%%%%%%%%

function [t,cp]=CpRange(tmin,tmax,inc)
inc=round(inc,3);%rounding to 3 decimal points
t=tmin:inc:tmax;
cp=zeros(size(t));
for i=1:length(cp)
cp(i)=CO2(t(i));
end
end

%%%%%%%%%%%%%%%SCRIPT%%%%%%%%%%%%%%%%%%%%%%%

i=1;
while i==1
fprintf('1. Cp for a given temperature\n2. A plot of Cp vs.T.\n3. Quit\n')
ch=input('Enter choice: ');
switch ch
case 1
t=input('Enter temperature value: ');
if t<300||t>3000
warning('Temperature must be between 300 to 3000 K!!')
  
else
cp=CO2(t);
fprintf('Temperature = %.2f K Cp = %.2f kJ/kg·K\n',t,cp)
end
case 2
tmin=input('Enter minimum temperature value: ');
if tmin<300||tmin>3000
warning('Temperature must be between 300 to 3000 K!!')
else
tmax=input('Enter maximum temperature value: ');
if tmax<300||tmax>3000
warning('Temperature must be between 300 to 3000 K!!')
else
inc=input('Enter temperature increment: ');
[t,cp]=CpRange(tmin,tmax,inc);
plot(t,cp);
xlabel('Temperature (K)')
ylabel('Specific Heat Capacity (kJ/kg·K)')
title('C_p vs t')
end
end
case 3
i=0;
end
end

OUTPUT

File d View nset Tools Desktop Window Help 1.02 ture must be betwees 300 3000 K 0 96 0 92 2-00 p 207620890-16 kg valaer 200 b

Add a comment
Know the answer?
Add Answer to:
Polynomial Curve Fitting Often we can assume that certain thermodynamic properties are constant for the process...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can you please follow all the instructions ? The answers that I got has either missing...

    can you please follow all the instructions ? The answers that I got has either missing range for loop or one funtion . Read the instructions carefully. At least 10% will be deducted if the instructions are not followed. For general lab requirements, see General Lab Requirements. Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input. Notes 1. Your program should use...

  • One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we...

    One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we will look at ways in which we can model geometric objects comprised of polygons. Here, we want to examine the interactive part. Let’s start by writing an application that will let the user specify a series of axis- aligned rectangles interactively. Each rectangle can be defined by two mouse positions at diagonally opposite corners. Consider the event listener canvas.addEventListener("mousedown", function() { gl.bindBuffer(gl.ARRAY_BUFFER, vBuffer); if...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT