Sie sind auf Seite 1von 10

EX:1 - Basic Commands & Scalar & Vector Functions Who Whos Clear all Clear <specific variable>

Help Disp Builtin functions (Scalar) sin trigonometric sine cos trigonometric cosine tan trigonometric tangent exp exponential log natural logarithm abs absolute value sqrt square root rem remainder round round towards nearest integer floor round towards negative infinity ceil round towards positive infinity Built in Vector functions max largest component min smallest component length length of a vector sort sort in ascending order sum sum of elements prod product of elements median median value mean mean value std standard deviation Basic Matrix functions size size of a matrix det determinant of a square matrix inv inverse of a matrix zeros ones diag eye rand

EX-2 rite t!e M"#$"B ex%ression of t!e follo&in' %ro(lem and sol)e it* !

"!

#! define the variable x as x $ #%&' then evaluate( a!

b!

c!

)! *wo trigonometric identities are given by( a! b! sin"x$"sinxcosx

for each part verify that the identity is correct by calculating each side of the equation' substituting x$&+"),pi%

EX +- ,ro(lems on "rra-s & Matrix: % Create a row vector that has the elements( #"' )' - ' e."%&' /#' cos01+#!%and "% Create a Column vector that has the elements( &&' )' ln0& !' 2-3'4' and &sin0"%&1!% #% Create a Column vector in which the first element is &' the elements decrease with increments of 5&' and the last element is 5"&% 06 column vector can be created by the transpose of a row vector!% )% Create a column vector with " equally spaced in which the first element is 5 and the last element is 5 &% &% Create the matrix shown below by using the vector notation or creating vectors with constant spacing and + or the linspace command when entering the rows )% "

/% Create the following matrix 6(

7se the matrix 6 to( a! Create a five element row vector named va that contains the elements of the second row of 6% b! Create a three5element row vector named vb that contains the elements of the fourth column of 6% c! Create a ten5element row vector named vc that contains the elements of the first and second rows of 6% d! Create a six5element row vector named vd that contains the elements of the second and fifth column of 6%

Ex.%

%Create the following matrix 6(

a! Create a # 8 ) matrix 9 from the st' #rd' and )th rows' and the st' #rd through &th and 3th columns of the matrix 6% b! Create a & elements5long row vector u from the elements of the third row' and the &th and 3th columns of the matrix 6% "% 7sing the zeros' ones' and eye commands create the following arrays(

#% 7sing the eye command create the array 6 shown on the left below% *hen' using the colon to address the elements in the array' change the array to be li:e the one shown on the right%

)% 7sing the zeros and ones commands create a # x & matrix in which the first' second' and fifth columns are 4;s' and the third and fourth columns are l;s% &% Create a & x 3 matrix in which the first row are the numbers " # ) & / 3' the second row are the numbers -2 4 " # )' the third row are the numbers & through " ' and so on% <rom this matrix create a new # x ) matrix that is made from rows " through )' and columns # through / of the first matrix%

/% Create a # x # matrix 6 in which all the elements are ' and create a " x " matrix 9 in which all the elements are &% *hen' add elements to the matrix 6 by appending the matrix 9 such that 6 will be(

EX/- Functions
%<unctions i% ii% iii% iv% v% vi% vii% =sequal =smember 7nique =ntersect Datestr Datevec Calendar0"4 4'-!

"% <ind your age using date functions% #% Display relevant message li:e >?ood @orning; or >?ood 6fternoon; or >?ood Avening; based on the current time using date functions%

EX0:Conditional Statments
% Display the grade of a student 7sing if Bthen5Alse o %>-4 5Dintintion o "%<-4 and >/4 B<irst class o #%</4 and >)& B== Class o )%<)& B <ail o <ind the given number is Cdd or Aven using if B then5else " # )% &% <ind the sum of natural numbers using <or loop <ind the sum of even numbers using <or loop <ind the sum of odd number using While loop Display =nterest rate for different account types using Dwitch Case <ixed Deposit 5 =nterest rate B E Fecurring Deposit B=nterest rate B - E Daving Deposit 5 =nterest rate B )E @ortgage Goan B =nterest rate B #E

EX 1 - 22 ,lots
1* 22 $ine ,lot =t also shows how to enter labels for the x and y axes using xlabel and ylabel as well as one method of initializing x5values% *ype doc linspace at the command prompt for information on another method for initializing evenly spaced data sets% Here y5values are computed as a function of x and stored in the variable y' but you could also plot Hust the computed y5values in one command' for example' plot(sin((0:0.05:5).^ ))% x$4(4%4&(&I y$sin0x%."!I plot0x'y!I xlabel0J*imeJ! ylabel0J6mplitudeJ! 2* Scatter >> x$4(4%4&(&I y$sin0x%."!I scatter0x'y!I xlabel0J*imeJ! ylabel0J6mplitudeJ! +* Bar ,lot you donJt need a variable to hold y5values if you pass a function that generates them to plot as its y5argument% x $ 5"%2(4%"( "%2I bar0x'exp05x%,x!!I .*Error(ar ,lot *he errorbar function draws a line plot of x and y values and superimposes on each observation a vertical error bar' the extent of which depends on an additional argument% Here the error data is created in line # using the rand function' which generates a sequence of random numbers% x$5"(4% ("I y$erf0x!I e $ rand0size0x!!+ 4I errorbar0x'y'e!I /*Stem ,lot 6 stem plot draws a mar:er for each x' y value which is connected to a common baseline by a vertical line%
x ! 0:0.":#$ y ! sin(x.^ ).%exp(&x)$ stem(x'y)

EX 3 - 22 ,lots
1* *he following table contains sales data of a company from 2-- to 22)% KA6F D6GAD 2-2-2 " 224 "4 22 "" 22" 22# ") 22) "3

Llot the graph for the table with das!ed (lac4 line5 mar:er type diamond ' line &idt! +' la(el the graph% 6lso create the vector for those data% 2* Llot the graph for the following data% Kear Llacement E "444 /& "44 3" "44" 3) "44# 3/ "44) -)

Llot the graph for the table with dotted red line 'mar:er type six pointed star 'mar:er edge colour green and mar:er size " and label the graph% 6lso create the vector for those data%

Das könnte Ihnen auch gefallen