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

CAE - Lab - Assignment - Questions

The document provides examples of MATLAB code for various tasks like defining vectors and matrices, performing operations on arrays, solving polynomial equations, conditional statements, loops, and curve fitting. A variety of fundamental MATLAB concepts and functions are demonstrated through examples and problems.

Uploaded by

Mt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

CAE - Lab - Assignment - Questions

The document provides examples of MATLAB code for various tasks like defining vectors and matrices, performing operations on arrays, solving polynomial equations, conditional statements, loops, and curve fitting. A variety of fundamental MATLAB concepts and functions are demonstrated through examples and problems.

Uploaded by

Mt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

CAE LAB Assignment - 001

MECH - A’21

1)
● A1 = [1,2,3,4,5] % A1 is vector
● A2 = [1 2 3 4 5] %A2 is vector same as A1
● B = [1,4,7;2,5,8;3,6,9] % B is matrix
● C = ‘Sitaram’ % Cis string
● length(C) ?
● C(1) ??
ans = ?
● Length(A)
● size(B) ?
● [m n] = size(B) ?
● A = rand(3,4) ?
● linspace(1:2:30) ___ starting value: difference: end value

2)
● A = [1 3 5; 2 4 6; 11 9 7; 3 4 5]
● A(3,1) % 3rd row , 1st column entry
● A(2,3) ??
● A =(i,:) it will write ith row of A
● A(2,:) ??
● A(:,j) it will write the jth column
● A(:,3) ??
● A(2:4,1:2) ?? it will write rows 2 to 4 and columns 1 to 2, thus , a 3x2
matrix returned as
● ans =??
● A([2 4], :) returns rows 2 and 4 and all columns. The output is a 2 × 3
matrix as follows:
● A([2 4], :)
A(:) returns one long column combining the columns of A as follows:
3)
● PROBLEM: Given an array A, the task is to exchange the second and
third rows of the array. >> A = [9 1 7; 2.5 7.5 12; 5 6.2 11];

4)
A=
3 2 9
5 1 0
4 6 7
B=
0 3 1
4 9 5
2 7 6

A(2 : 3, 1 : 2) ??
5)
PROBLEM: Given an array A, the task is to exchange the second and third
rows of the array. >> A = [9 1 7; 2.5 7.5 12; 5 6.2 11];
6)
● What is the output when you execute the following
command?
>> A = [1:2:9; 2:2:10; 11:-2:3; 3:7]
7)

PROBLEM:

8)
>> X = [1; 4; 5];
>> Y = [3; 2; 1];
>> cross(X,Y)
ans =
9)
Cells

a = {}; a = cell(1)
B = {1,2,3}
C = {{1,2},2,{3}}
D = {‘cat’,’dog,’sheep’,’cow’)
E = {‘cat’,4}

D{2} =??
E{1} =??
E{2} =??

10)

>>p2 = [1 -7 16 25 52]
>>roots_p2 = roots(p2) ???

11)
>> r3=[1 2 3 4] % Specify the roots of the polynomial
>> poly_r3 = poly(r3)
After finding polynomial eqn, then verify that

>> A = poly_r3
>>roots_A = roots(A) ??
12)

r4 = [ -1 -2 -3 4+5j 4-5j ] ??
13)
Evaluate the polynomial p5( ) x = x^6 – 3x^5 + 5x^3 – 4x^2 +2 at x = -3.

>> p5=[1 -3 0 5 -4 3 2];


● >> val_minus3=polyval(p5, -3) ??
14)
A = [1 2 3; 4 5 6]; B = [7 8 9; 0 1 2]; Verify the condition A>B|B>5
15)
What will be the output of the following commands?
(a) A = [1,2;3,4]; B = [A 2*A], (b) A(1,:), (c) B(:,2)
(d) E = [A,B], (e) F = [A;B], (f) A([1,2],:)= A([2,1],:)

16)

17)
Given a linear formula: Y = 3x + 7. Create an m-file for plot ‘y’ versus ‘x’.

18)
a = 3; b = 2;
if (a > b) disp ('a is larger'); disp('b is smaller');
end
c=5
19)
day = input('Enter a number for the day (1to 7)');
if(day == 1)
disp ('Monday')
elseif (day == 2)
disp ('Tuesday')
elseif (day == 3)
disp ('Wednesday')
End

20)

method = 'divison';
switch lower(method)
case {'adition'}
x1=4;
x2=5;
x3=5;
y1=x1+x2+x3
disp('Method is add')
case 'subtraction'
x1=40;
x2=5;
x3=5;
y1=x1-x2-x3
case 'divison'
x1=40;
x2=5;
x3=5;
y1=x1/x3
disp('Method is division')
otherwise
disp('Unknown method.’)

21)
You can write a code for solving the problems using 1st , 2nd , 3rd and 4th
order polynomial equations

% factorial using a for loop


n = input ('input the number :');
fact_n = 1; % initialization of the variable fact_n
for i = 1: n
fact_n = fact_n * i
end
disp('factorial of the number is :')
disp (fact_n);

%USING WHILE LOOP


% factorial using a while loop
n = input ('input the number :');
fact_n = n; i = 1;
while i <= (n - 1)
fact_n = fact_n * i;
i = i + 1;
end
disp ('factorial of the number is :'),disp (fact_n);

22)
QUESTIONS

1. Download the Thermocouples "R and K type" data, then do the curve fitting using data "Millivolts
Vs Degree C " to find the empirical equations..

2. Create graph or plot in the excel using 2nd and 3rd order polynomial equations, then this excel data
can be verified with data fitting concept using MATLAB.

**THE END**

You might also like