0% found this document useful (0 votes)
41 views4 pages

Sheet 2

Uploaded by

mahmoud amin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views4 pages

Sheet 2

Uploaded by

mahmoud amin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

BENHA UNIVERSITY Faculty of engineering

Computer
Programming
Mechanical engineering department 3rd year (Power)

Assignment (2)
1- Identify the error in each of the following statements and correct
the wrong ones
a) n + 1 = n;
Fahrenheit temp = 9*C/5 + 32;
2 = x;
b) z = 2 + 3 i
z=6+j5
c) x = 0.01 : .001; .1;
plot (x, sin(1/x))
d) x = 0 : 0.1 : 10;
z = sin x;
plot (x,y), grid
e) x = 0 : pi/20 : 6 * pi;
plot(x, exp(-0.2*x) * sin(x), ’r’), grid
f) ploty(x,sin(x), x, 10*cos(x)) % independent left and right y-axis labels
g) t = (0:.1:2*pi)’;
subplot(2,2,1), plot(t sin(t))
subplot(2,2,2), plot(t,cos(t))
subplot(2,2,3), plot(t,exp(t)
subplot(2,2,5), plot(t,1./(1+t. ^2))
h) x = -1:0.001:1;
y1 = acos(x);
y2 = asin(x);
y3 = atan(x);
plot(y1,x,y2,x,y3 x), grid,
legend(’asin(x)’, acos(x)’, ’atan(x)’)
xlabel(’\theta in radian’), ylabel(’x, the argument of the function’)

Dr. Mohamed Saber Sokar 1/4


2- Suppose you have $1000 initial investment saved in the bank. Interest is
compounded at the rate of 9 % per year. Use the simple interest formula
A = P (1+ n . i)
Draw a flow chart and write a MATLAB program to find final amount of the
new balance after one year
3- If C and F are Celsius and Fahrenheit temperatures respectively, the
formula for conversion from Celsius to Fahrenheit is F =9 C/5+32.
- Write a script which will ask for the Celsius temperature and display the
equivalent Fahrenheit one with some sort of comment, e.g. The
Fahrenheit temperature is: ...
- Try it out on the following Celsius temperatures (answers in brackets):
0, 100, −40, 37 (normal human temperature).
4- Write the equivalent mathematical function or meaning for each MATLAB
Functions and Variables in the table
Hint: Fill as solved in the first and last rows in the following table
Function Remark Function Remark
Cos (x) Cosine of x log(x) Natural logarithm base (e)
sin(x) log10(x)
tan(x) abs(x)
acos(x) real(x)
asin(x) imag(x)
atan(x) angle(x)
atan2(y,x) conj(x)
cosh(x) round(x)
sinh(x) sqrt(x)
tanh(x) sign(x)
acosh(x) clock
asinh(x) mod(y,x)
atanh(x) floor(x)
exp(x) ceil(x)
cot(x) cotangent of x. csc(x) cosecant of x.

Dr. Mohamed Saber Sokar 2/4


5- A boiled milk is initially (i.e. t=0) at a temperature of T0= 100°C, is placed
inside a refrigerator where the temperature is TS=4°C.
Hint: The temperature of an object changes according to the equation:
T = TS + (T0 – TS) e-k t
Where, T is the temperature of the object at time t (seconds), and assume
the constant k = 0.0004.
- Plot the temperature over interval of 3 hours using MATLAB m-file, add
x-, y-axis and figure title.
- Determine to the nearest degree, in the same program, the temperature
of the milk after two hours.

6- Draw a flowchart to plot the function y = 3x3–26x + 10, and its first and
second derivatives in the same plot during the interval -2≤ x ≤ 4.
User Matlab command to add x-axis title (x) and diagram title (A plot of the
function y = 3x^3 - 26x + 10 and its first and second derivatives)
Display also the legend on the diagram as follows; first legend ( y = 3x^3 -
26x + 10), Second legend (yd = 9x^2 – 26), third legend (ydd = 18x)

7- Run the following MATLAB program and copy the resulting curves in your
answer sheet
A)
% program indicating plot options
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2, 'MarkerEdgeColor','k',...
'MarkerFaceColor','g', 'MarkerSize',10)

B)
x = 0:pi/40:2*pi;
polar(x, sin(2*x)),grid
C)

Dr. Mohamed Saber Sokar 3/4


t = 0:pi/20:2*pi;
y1 = exp(sin(t));
y2 = exp(cos(t));
plotyy(t,y1,t,y2,'plot','stem')
xlabel('X Axis')
ylabel('Plot Y Axis')
title('Two Y Axes')
grid on
D)

q0 = 10;R = 50;L = 5;C = 1e-4;


t = linspace(0,.5);
q = q0*exp(-R*t/(2*L)).*cos(sqrt(1/(L*C)-(R/(2*L))^2)*t);
plot(t,q)
grid
xlabel ('value of t')
ylabel ('value of q')
E)

t = (0:.1:2*pi);
subplot(2,2,1), plot(t,sin(t))
subplot(2,2,4), plot(t,1./(1+t.^2))
subplot(2,2,3), plot(t,exp(t))
subplot(2,2,2), plot(t,cos(t))
F)

t = -1:0.001:1;
y1 = acos(x)*180/pi; y2 = asin(x) *180/pi; y3 = atan(x) *180/pi;
plot(y1,t,y2,t,y3, t),grid,
legend('asin(x)', 'acos(x)', 'atan(x)')
xlabel('\theta in degrees'),ylabel('x, the argument of the function')

Dr. Mohamed Saber Sokar 4/4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy