Você está na página 1de 6

QUESTION1

Given two sides a=3.2 and b=4.6 of a triangle and angle =60 between a and b . find the length of third
side and area of triangle.

SOLUTION

a=3.2;
b=4.6;
c=sqrt(a^2+b^2-(2*a*b*1/2))
c =4.0841

QUESTION2

Write the programme to convert temp given in degree Celsius to Fahrenheit say 35.4C

SOLUTION

c=35.4
f=(c*9/5)+32
f =

95.7200
QUESTION3

Write matlab code to calculate the sum of series for x=1.5

𝑥2 𝑥4 𝑥6 𝑥8
𝑠 =1− + − +
2! 4! 6! 8!

SOLUTION

x=1.5;
s=1-(x^2/factorial(2))+(x^4/factorial(4))-
(x^6/factorial(6))+(x^8/factorial(8))

s =

0.0708
QUESTION

Write a script to prompt the user to enter a numeric value .Again prompt the user about the sign of the
number.

SOLUTION

EDITOR WINDOW

x=input('please enter a numeric value\n');


if x>0
fprintf('you have entered a positive value %d',x)
else
fprintf('you have entered a negative value %d',x)
end

COMMAND WINDOW

>>please enter a numeric value


-5
you have entered a negative value -5
>>please enter a numeric value
5
you have entered a positive value 5

QUESTION

Write the script to prompt the user to enter a numeric value and prompt the user if it is a positive value

SOLUTION

EDITOR WINDOW

x=input('please enter a numeric value\n');


if x<0
y=abs(x);
fprintf('you have entered a NEGATIVE value %d\n',x)
end
fprint('hence the modulus of the value entered by you is %d\n',y)

COMMAND WINDOW

please enter a numeric value


-2
you have entered a NEGATIVE value -2
hence the modulus of the value entered by you is 2

QUESTION

Function to take value and create a vector using colon operator with the two values (usinf only if
statement)

SOLUTION

EDITOR WINDOW

function vector=values(x1,x2)
vector=(x1:x2);

COMMAND WINDOW
values(2,5)
ans =

2 3 4 5

QUESTION

Prompt the user for a number to calculate its squae . if the number is negative ,convert it into positive
value and then calculate its square

SOLUTION

EDITOR WINDOW

x=input('please enter a numeric value\n');


y=x^2;
if x<0
fprintf('you have entered a negative value %d\n',x)
z=abs(x);
y=z^2;
end
fprintf('the square of the number entered by you is = %d\n',y)

COMMAND WINDOW

please enter a numeric value


-5
you have entered a negative value -5
the square of the number entered by you is = 25
please enter a numeric value
5
the square of the number entered by you is = 25

QUESTION

Write a program to calculate the following

𝑦 = 2𝑥 2 + 1 for x<5

Otherwise 𝑦 = 3𝑥

SOLUTION

EDITOR WINDOW

x=input('please enter a numeric value\n');


if x<5;
y=2*(x^2)+1;
else y=3*x;
end
fprintf('the value of y if = %d\n',y)
COMMAND WINDOW

please enter a numeric value


5
the value of y if = 15
please enter a numeric value
2
the value of y if = 9

QUESTION

Print the pattern

*****

*****

*****

*****

SOLUTION

EDITOR WINDOW

for i=1:4;
for j=1:5;
fprintf('*')
end;
fprintf('\n')
end

COMMAND WINDOW

*****

*****

*****

*****

QUESTION

Write a program to illustrate the use of error statement.When a error is ncounterd during the addition
of two row vector.check the programe for th following data

1)A=[2 3] B=[23 45]

2)A=[12 37] B=[23 2 56 37]


SOLUTION

EDITOR WINDOW

QUESTION

Plot function 𝑥 = 𝑒 −𝑎 ,𝑦 = 𝑎2 where 0≤a≤10 using semilog function

SOLUTION

EDITOR WINDOW

a=[0 10];
x=exp(-a);
y=a.^2;
semilogx(x,y)
title('plot x verus y'),xlabel('x axis'),ylabel('y axis')
grid on

GRAPH

plot x verus y
100

90

80

70

60
y axis

50

40

30

20

10

0
-5 -4 -3 -2 -1 0
10 10 10 10 10 10
x axis

QUESTION
Plot power v/s time for 0<t<8sec, with power on the logscale and time in the linear scale for a motor
whose performance equation are given as

i)Rotational speed w = 109(1 − e−0.15t )

ii)Torque 𝑡 = 8𝑒 −0.15𝑡

iii)power p=wt

Você também pode gostar