Sie sind auf Seite 1von 4

VERCELES, MARK IRVIN P.

PROBLEM:
2) Create an x vector that has integers 1 through 10, and set a y vector equal to x. Plot this
straight line. Now, add noise to the data points by creating a new y2 vector that stores the values
of y plus or minus 0.25. Plot the straight line and also these noisy points.

SCRIPT FILE:
x = 1:10;
y = x;
y2(1:2:9) = y(1:2:9) + 0.25;
y2(2:2:10) = y(2:2:10) - 0.25;
plot(x, y, x, y2), legend('y', 'y2')

VERCELES, MARK IRVIN P.

PROBLEM:
13.Write a script that will print the following multiplication table:
1
24
369
4812 16
5 10 15 20 25

SCRIPT FILE:
for i = 1:5
for v = 1:i
fprintf('%d ', v * i);
end
fprintf('\n');
end

VERCELES, MARK IRVIN P.

PROBLEM:
24. 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

Where TC and TH are the absolute temperatures at the cold and hot reservoirs, respectively.
Write a script that will prompt the user for the two reservoir temperatures in Kelvin and print the
corresponding Carnot efficiency to three decimal places. The script should error-check the users
input as absolute temperature cannot be _ 0. The script should also swap the temperature values
if
TH is less than TC.

SCRIPT FILE:
x=(1:9)'
a=repmat(x,1,9)
b=a'
c=bsxfun(@times,x,x')
out=arrayfun(@(x,y,z) [num2str(x) 'x' num2str(y) '=' num2str(z)],a,b,c,'un',0)

VERCELES, MARK IRVIN P.


PROBLEM:

46. Write a Guess My Number Game program. The program generates a random integer in a
specified range and the user (the player) has to guess the number. The program allows the user to
play as many times as he/she would like; at the conclusion of each game, the program asks
whether the player wants to play again.
The basic algorithm is as follows.
1. The program starts by printing instructions on the screen.
2. For every game:
n the program generates a new random integer in the range from MIN to MAX. Treat MIN and
MAX like constants; start by initializing them to 1 and 100
n loop to prompt the player for a guess until the player correctly guesses the integer
n for each guess, the program prints whether the players guess was too low, too high, or correct.
At the conclusion (when the integer has been guessed):
n print the total number of guesses for that game.
n print a message regarding how well the player did in that game (e.g., the player took way too
long to guess the number, the player was awesome, etc.); to do this, you will have to decide on
ranges for your messages and give a rationale for your decision in a comment in the program.
3. After all games have been played, print a summary showing the average number of guesses.

SCRIPT FILE:
function g=guess(f,N)
% returns N+1 values as inputs from user
g=zeros(N+1,1);
for i=1:N+1
g(i)=input(['Enter guess ' num2str(i) ': '])
end

Das könnte Ihnen auch gefallen