Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Numerical and Computer Tools I Summer 2023

Homework 2

1.   Consider matrix [A] =  6   7   9|. (a) Obtain the inverse of [A] and (b) the solution of

the system [A][x] = [b], where [x] = x2| and [b] =  3 |

x1                             7

x3 5

2.   Experiment, in the Matlab Command window, with the fprintf function for real numbers and report what happens for each. Use fprintf to print the real number 12345.6789.

•   Without specifying any field width

•   In a field width of 10 with 4 decimal places

•   In a field width of 10 with 2 decimal places

•   In a field width of 6 with 4 decimal places

•   In a field width of 2 with 4 decimal places

3.   Experiment, in the Matlab Command window, with the fprintf function for integers and report what happens for each. Use fprintf to print the integer 12345.

•   Without specifying any field width

•   In a field width of 5

•   In a field width of 8

In a field width of 3

4.   Write a script called echostring that will prompt the user for a string of characters, and will print the string in quotes:

>> echostring

Enter your string: hi there

Your string was: ‘hi there

Your script should be well-commented.

5.   If the lengths of two sides of a triangle and the angle between them are known, the length of the third side can be calculated. Given the lengths of the two sides (b and c) of a triangle, and the angle between them a in degrees, the third side a is calculated as follows:

a2  = b2 + c2 − 2bc cos (a)

Write a script thirdside that will prompt the user and read in values for b, c and a (in degrees), and then calculate and print the value of a, with 3 decimal places. The format of the output from the script should look exactly like this.

>>thirdside

Enter the first side : 2.2

Enter the second side : 4.4

Enter the angle between them : 50

The third side is 3.429

Your script should be well-commented.

6.   Renewable energy  sources  such as biomass are gaining increasing attention. Biomass energy units include megawatt hours (MWh) and gigajoules (GJ). One MWh is equivalent to 3.6 GJ. For example, one cubic meter of wood chips produces 1 MWh. Write a script mwh_to_gj that will prompt the user to enter an amount of wood chips in cubic meters and will output the corresponding energy produced in MWh and in GJ. The input and output

should be printed in sentence form.

Your script should be well-commented.

7.   The conversion depends on the temperature and other factors, but an approximation is that

1 in. of rain is equivalent to 6.5 in. of snow. Write a script that prompts the user for the number of inches of rain and outputs the equivalent amount of snow, and prints this result.

The input and output should be printed in sentence form.

Your script should be well-commented.

8.   In thermodynamics, the Carnot efficiency is the maximum possible efficiency of a heat engine operating between two reservoirs at different temperatures. The Carnot efficiency is given as

= 1 −

where Tc and TH are the absolute temperatures at the cold and hot reservoirs, respectively. Write a script carnot that will prompt the user for the two reservoir temperatures in Kelvin and outputs the Carnot efficiency to 3 decimal places. The input and output should be printed in sentence form.

Your script should be well-commented.