APCS 345 Numerical Analysis Methods (MATLAB) Project #1 Fall 2017 A. Methane Fue
ID: 3601181 • Letter: A
Question
APCS 345 Numerical Analysis Methods (MATLAB) Project #1 Fall 2017 A. Methane Fuel Tank Capacity than the ideal gas law for real gases and is given by Select to do either option A or B Kwong equation of state, similar to the Van der Waals equation, is a much better approximation RT v(v + b) VT where -b P represents the absolute pressure (kPa) v is volume per kilogram of the gas (mkg) a-0.427 RT/P R represents the universal gas constant (0.518 kJ/kgK) is the most useful form here) T is absolute temperature (K) and and b=0.0866 RT,/P for methane, Pe is 4600 kPa and Te is 191 K mass of methane fuel that can be held in various size You have been asked to help a company determine the tanks filled at different pressures and temperatures. The engineers are familiar with the use of MATLAB commands, but not the programming of m-files. They have two requests. 1) They want to be able to call a function methaneMass from the Command Window, specifying the parameters of volume of the tank in m, the pressure in kPa, and the temperature in C. and get the mass of methane contained, in kg and pounds, correct to three decimal places. For example, they would type methaneMass (3.0, 65e3,-41) and then see Methane mass-mmmg or m , ib nan.nm 2) They want to be able to print out tables of the mass to 2 decimal places, in kg, for a given tank volume at various pressures and temperatures. They want to be able to respond to prompts and type in the volume of the tank (which will be divided into 10 values) and receive a table with various pressures as column headings and temperatures as row identifiers. For example, Mass of Methane contained in a vww Volume tank T.K/ P.kPa 60000 220 64000 68000 230 235 240 245 250 260 265 270 of course, they would also like to see a graph of the mass as a variation of temperature, for the 3 different pressures, all on the same plot. Therefore your task is to write 2 MATLAB m-files 1) methane Mass, which accepts parameters and outputs 2 values 2) methaneTable, which has prompted input and outputs a table and a graphExplanation / Answer
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#define ERR (-1)
#define TRUE 1
#define FALSE 0
int main();
int main(argc, argv)
int argc;
char *argv[];
{
int isdevice = FALSE;
struct stat stat_buf;
if (argc != 2)
{
printf("Usage: %s filename ", argv[0]);
exit (1);
}
if ( stat( argv[1], &stat_buf) == ERR)
{
perror("stat");
exit (1);
}
printf(" File: %s status: ",argv[1]);
if ((stat_buf.st_mode & S_IFMT) == S_IFDIR)
printf("Directory ");
else if ((stat_buf.st_mode & S_IFMT) == S_IFBLK)
{
printf("Block special file ");
isdevice = TRUE;
}
else if ((stat_buf.st_mode & S_IFMT) == S_IFCHR)
{
printf("Character special file ");
isdevice = TRUE;
}
else if ((stat_buf.st_mode & S_IFMT) == S_IFREG)
printf("Ordinary file ");
else if ((stat_buf.st_mode & S_IFMT) == S_IFIFO)
printf("FIFO ")
if (isdevice)
printf("Device number:%d, %d ", (stat_buf.st_rdev > 8) & 0377,
stat_buf.st_rdev & 0377);
printf("Resides on device:%d, %d ", (stat_buf.st_dev > 8) & 0377,
stat_buf.st_dev & 0377);
printf("I-node: %d; Links: %d; Size: %ld ", stat_buf.st_ino,
stat_buf.st_nlink, stat_buf.st_size);
if ((stat_buf.st_mode & S_ISUID) == S_ISUID)
printf("Set-user-ID ");
if ((stat_buf.st_mode & S_ISGID) == S_ISGID)
printf("Set-group-ID ");
if ((stat_buf.st_mode & S_ISVTX) == S_ISVTX)
printf("Sticky-bit set -- save swapped text after use ");
printf("Permissions: %o ", stat_buf.st_mode & 0777);
exit (0);
}