SIP EX
SIP EX
EC23B1126
EXERCISE 1:
Build a VI to compute the variance of an array x. The variance σ is defined as:
where μ denotes the average of the array x. For x, use all the integers from 1 to 1000.
OUTPUT:
The following output shows the formula of variance.It is given that x ranges 1to 1000.So,
we need to create for loop and constant of 1000 for N. Incremeted I inside the loop. We
get the size of the array using array size given in the function . The values are being
summed using summation function . We divide the summed numbers by the array size
to get average which is denoted by µ .Average value is subtracted and square them .then
the value is summed and divided by the array size .
EXERCISE 2:
Build a VI to check whether a given positive integer n is a prime number and display
awarning message if it is not a prime number.
OUTPUT:
The following output shows whether the given number is prime number or not a prime
number .Here led will glow if it is not a prime number . The number is given by us and
divide the given number till 1 to given number . The boolean 0 to 1 we convert true to 1
and false to 0 . The summation will 2 prime number has only 2 cases .if the remainder is
0 then it is a prime number otherwise, not a prime number .
EXERCISE 3:
Build a VI to generate the first N prime numbers and store them using an indexing
array.Display the outcome.
OUTPUT:
The following output shows that how to generate the prime number and store them in
indexing array . We have to divide the odd number with smaller than them . if the
remainder is zero then loop terminates .if the number is equal to the number of iteration
and we will add number in array.
EXERCISE 4:
Build a VI to sort N integer numbers (positive or negative) in ascending or descending
order.
OUTPUT:
The question says that we have to sort integers into ascending or descending order .we
have to take for loop and we can take any number. For this we will use sort 1-D array. We
will give random numbers in the input and the output will be in ascending order sorted
1D array.
EXERCISE 5:
Write a .m file code to add all the numbers corresponding to the even indices of an
array.For instance, if the array x is specified as x = [1, 3, 5, 10], then 13 (= 3+10) should
bereturned. Use the program to find the sum of all even integers from 1 to 1000. Run
yourcode using the LabVIEW MathScript interactive window. Also, redo the code where
x is theinput vector and y is the sum of all the numbers corresponding to the even
indices of x.
OUTPUT:
We have to write a m.file code to generate the sum of number present in the indices.We
have to take a array and store it in x . For every 2 index till end , we add the number
present in x .Likewise we have to take an array from 1 to 1000 , we will able to find the
sum of even number by same method .
EXERCISE 6 :
Explain what the following .m file does:
L=length(x);
for j=1:L
if x(j) < 0
x(j)=-x(j);
end
end
Rewrite this program without using a for loop.
OUTPUT:
We have to write m.file to calculate the length of a vector x and stores it in the variable L
. In this it will enter in the loop that iterates through each element of a vector .it checks
whether indexed j is less than 0.If this is true then code negates with value of element .
it will the negative elements with absolutes value . the vector is sorted back in variable x
. We substitute x(n)=-x(n) where n denote the value less than zero.
EXERCISE 7 :
For t, use 1000 random numbers generated via the function rand.
OUTPUT:
This code gerates 1000 random numbers using random function. Random numers are
uniformly distributed between 0 and 1 . If the value t is greater than or equal to 0.2 then
the corresponding element x is set as 0.2 . If the value t is less than to 0.2 then the
corresponding element x is set as -0.2 .the result will be x and originally generated
random numbers .
EXERCISE 8 :
Build a hybrid VI to generate two sinusoid signals with the frequencies f1 Hz and f2 Hz
and the amplitudes A1 and A2, based on a sampling frequency of 8000 Hz with the
number of samples being 256. Set the frequency ranges from 100 to 400 Hz and set the
amplitude ranges from 20 to 200. Generate a third signal with the frequency f3 = (mod
(lcm (f1, f2), 400)+ 100) Hz, where mod and lcm denote the modulus and least common
multiple operation,respectively, and the amplitude A3 is the sum of the amplitudes A1
and A2. Use the samesampling frequency and number of samples as specified for the
first two signals. Display allthe signals using the legend on the same waveform graph
and label them accordingly.
OUTPUT:
In this we are using mathscript where in code f1 to f2 has given the range of 10 to 100.
and Amplitude A1 to A2 range of 20 to 200 . we will selected randomly select frequency
and amplitude applied in the given conditional of the third sine wave by this we will get
output as shown above .