Search This Blog

Tuesday, September 13, 2016

Design an x-y plot for the following where the values of x are from 0 to 20pi with a spacing of pi/100.

Question:


       Design an x-y plot for the following where the values of x are from 0 to 20pi with a spacing of           pi/100.
a.           y=x.sin(x)
b.          z=x.cos(x)

c.          convert the above 2D into a 3D plot using z as the third axis

To accept two numbers from the user and display Armstrong numbers between these two numbers

Question:


To accept two numbers from the user and display Armstrong numbers between these two numbers

  Answer:

a = input(' Enter your 1st number: ');
b = input('\n Enter your 2st number: ');

for i = a:b
if isprime(i)
fprintf('%d, ', i)
end
end
fprintf('\n')

Output:

                  Enter your 1st number: 1
                  Enter your 2st number: 100

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 

To accept two numbers from the user and display perfect numbers between these two numbers


Question:

To accept two numbers from the user and display perfect numbers between these two numbers


clc
num1 =input(' Enter your 1st number: ');
num2 =input('\n Enter your 2st number: ');
output = zeros(1,num2);
for i = num1:num2
if true
end

test = 1:i-1;
if (sum(test(mod(i,test) == 0)) == i)
output(i) = i;
end
end

output(output == 0) = []

Output: I just write in command window

       
                  Enter your 1st number : 1
                      Enter your 2st number : 100


       output =

                      6    28




To accept two numbers from the user, display all prime numbers between these two numbers.

Question:

To accept two numbers from the user, display all prime numbers between these two numbers.


     Answer:


    clc
    num1 =input(' Enter your 1st number: ');
    num2 =input('\n Enter your 2st number: ');
    n = num1 : num2;
    p = isprime(n);
    n(p)    %displays the prime numbers

Output: I write down in command window


               Enter your 1st number: 1
                  Enter your 2st number: 100            ;then push enter

              ans =

  Columns 1 through 19
2     3     5     7    11    13    17    19    23    29    31    37    41    43    47    53    59    61    67
Columns 20 through 25
      71    73    79    83    89    97









Write a MATLAB script to display currency conversion for US Dollar, British Pound, Euro with Singapore Dollar as the base Currency. Your output should show the equivalent values for USD, GBP, EURO for every Singapore dollar in increments of 1 dollar until 25 dollars.

Question: 

Write a MATLAB script to display currency conversion for US Dollar, British Pound, Euro with Singapore  Dollar as the base Currency. Your output should show the equivalent values for USD, GBP, EURO for every Singapore dollar in increments of 1 dollar until 25 dollars.

Sample Output to be as follows:

     SGD    USD    GBP    EURO
       1          -           -           -
       2          -           -           -
       3          -           -           -
        .          .
        .          .
      25          -           -           -


Answer:


clc
clear all
fprintf(' \n  SGD...  USD      GBP      EURO\n\n');

for (SGD=1:25)
        USD = SGD*0.740;
        GBP = SGD*0.550;
        EURO = SGD*0.660;
        fprintf('%3d  =  %5.2f    %5.2f     %5.2f\n', SGD, USD, GBP, EURO);


end


[ N.B:
This question may have different answer, but this one is very easy & you have to   just change dollar rate respect to USD,  GBP, EURO ]