0% found this document useful (0 votes)
77 views

CS10-8 Assignment ControlStructures

The document provides examples of MATLAB expressions to evaluate if they are true or false and includes a code sample to write a program that uses a for loop to tabulate the square, square root, and exponent of positive integers.

Uploaded by

Andrew Tolentino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

CS10-8 Assignment ControlStructures

The document provides examples of MATLAB expressions to evaluate if they are true or false and includes a code sample to write a program that uses a for loop to tabulate the square, square root, and exponent of positive integers.

Uploaded by

Andrew Tolentino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CS10-8 / A24

Evaluate the following MATLAB expressions.

FALSE (a) 5>=5.5

TRUE (b) 20>20

FALSE (c) (17 - < 15,pi < 3)

TRUE (d) true > false

FALSE (e) ~~(35 / 17) = = (35 / 17)

FALSE (f) (7 < = 8) = = (3 / 2 = = 1)

TRUE (g) 17.5 && (3.3 > 2.)

Write a program, TabRoots.m, that uses a for loop to tabulate for each positive integer n, its
square, square root, and en. The output should look like this:
n= 1
      sqrt(n)= 1
      nˆ2= 1
      exp(n)= 2.7183
n= 2
     sqrt(n)=1.4142
     nˆ2= 4
     exp(n)= 7.3891
n= 3
     sqrt(n)= 1.7321
     nˆ2= 9
     exp(n)= 20.0855
n= 4
    sqrt(n)= 2
    nˆ2= 16
    exp(n)= 54.5982
n= 5
    sqrt(n)= 2.2361
    nˆ2=25
    exp(n)= 148.4132

Attached your TabRoots.m file


Script Code:

%%TabRoots.m
%This program calculates the square, square root
%and exponent nth times
num=input('Input an integer number: ');
for x=1: num
sqr=x^2;
sqrt=(sqrt(x));
ex=exp(x);
disp(['n= ', num2str(x)]);
disp(['square of ', num2str(x),' is ' num2str(sqr)]);
disp(['square root of ',num2str(x),' is ' num2str(sqrt)]);
disp(['exponent of ', num2str(x), ' is ' num2str(ex)]);
end

>> TabRoots
Input an integer number: 1
n= 1
square of 1 is 1
square root of 1 is 1
exponent of 1 is 2.7183
>>

You might also like