Professional Documents
Culture Documents
Experiment No 5
Experiment No 5
5
Loop statements
%calculating factorial
1_x=input('type number:');
fact=1; while 1_x>1
fact=fact*1_x;
1_x=1_x-1; end disp(fact)
type number:5
120
Cell Arrays
doc_profile =
3×36 char array
'1 '
'Sr. Surgeon '
'RN Tagore Cardiology Research Center'
Combining strings
name = '1 ';
position = 'Sr. Surgeon
';
worksAt = 'R N Tagore Cardiology Research
Center'; profile = [name ', ' position ', ' worksAt]
profile = strcat(name, ', ', position, ', ', worksAt)
profile =
'1 , Sr. Surgeon , R N Tagore Cardiology Research Center'
profile =
'1,Sr. Surgeon,R N Tagore Cardiology Research Center'
{'1' }
{'Sr. Surgeon' }
{'R N Tagore Cardiology Research Center'}
String functions
PLOTTING
1_x=[-2:0.2:4];
1_y=2*1_x.^3 - 7*1_x.^2 + 5*1_x.^1;
1_yd=6*1_x.^2 - 14*1_x + 5; 1_ydd=12*1_x -
14;
plot (1_x,1_y,'-
mo','LineWidth',2,'markersize',8,'markerfacecol
or','y') hold on xlabel('TIME (s)')
ylabel('FUNCTION')
title('\fontname{hello}Distance Velocity and
Acceleration as a function of
Time','Fontsize',15) axis([-2.5,4.5,-65,65])
gtext('Function 2x^3-7x^2+5x and its
derivarives','EdgeColor','k','LineWidth',2,'Fontsi
ze',15) plot (1_x,1_yd,'--
bv','LineWidth',2,'markersize',8,'MarkerEdgeCo
lor','b','markerfacecolor','r') hold on
plot(1_x,1_ydd,':ko','LineWidth',2,'markersize',
8,'MarkerEdgeColor','g','markerfacecolor','m')
legend('Distance','Velocity','Acceleration','Locat
ion','southeast','Fontsize',15) grid on hold off