Home » Blog » Problem Solving MATLAB Part 2 Chapman Book

# Problem Solving MATLAB Part 2 Chapman Book

Q-1. Assume that a, b, c, and d are defined as follows, and calculate the results of the following operations if they are legal. If an operation is illegal, explain why it is illegal.

(a) result = a + b;

(b) result = a * d;

(c) result = a .* d;

(d) result = a * c;

(e) result = a .* c;

(f ) result = a \ b;

(g) result = a .\ b;

(h) result = a .^ b;

``````clc;
clear all;
close all;

a = [2 1; -1 4];
b = [-1 3; 0 2];
c = [2; 1];
d = eye(2);

disp('a = ');
disp(a);
disp('b = ');
disp(b);
disp('c = ');
disp(c);
disp('d = ');
disp(d);

result1 = a + b;
fprintf("a + b = \n");
disp(result1);
result2 = a * d;
fprintf("a * d = \n");
disp(result2);
result3 = a .* d;
fprintf("a .* d = \n");
disp(result3);
result4 = a * c;
fprintf("a * c = \n");
disp(result4);
result5 = a .* c;
fprintf("a .* c = \n");
disp(result5);
result6 = a \ b;
fprintf("a \\ b = \n");
disp(result6);
result7 = a .\ b;
fprintf("a .\\ b = \n");
disp(result7);
result8 = a .^ b;
fprintf("a .^ b = \n");
disp(result8);``````

Output

Q-2. Evaluate each of the following expressions:

(a) 11 / 5 + 6

(b) (11 / 5) + 6

(c) 11 / (5 + 6)

(d) 3 ^ 2 ^ 3

(e) 3 ^ (2 ^ 3)

(f ) (3 ^ 2) ^ 3

(g) round(-11/5) + 6

(h) ceil(-11/5) + 6

(i) floor(-11/5) + 6

``````clc;
clear all;
close all;

aa = 11 / 5 + 6;
disp(aa);
aa = (11 / 5) + 6;
disp(aa);
aa = 11 / (5 + 6);
disp(aa);
aa = 3 ^ 2 ^ 3;
disp(aa);
aa = 3 ^ (2 ^ 3);
disp(aa);
aa = (3 ^ 2) ^ 3;
disp(aa);
aa = round(-11/5) + 6;
disp(aa);
aa = ceil(-11/5) + 6;
disp(aa);
aa = floor(-11/5) + 6;
disp(aa);``````

Output

Q-3. Solve the following system of simultaneous equations for x:

-2.0 x1 + 5.0 x2 + 1.0 x3 + 3.0 x4 + 4.0 x5 – 1.0 x6 = 0.0

2.0 x1 – 1.0 x2 – 5.0 x3 – 2.0 x4 + 6.0 x5 + 4.0 x6 = 1.0

-1.0 x1 + 6.0 x2 – 4.0 x3 – 5.0 x4 + 3.0 x5 – 1.0 x6 = -6.0

4.0 x1 + 3.0 x2 – 6.0 x3 – 5.0 x4 – 2.0 x5 – 2.0 x6 = 10.0

-3.0 x1 + 6.0 x2 + 4.0 x3 + 2.0 x4 – 6.0 x5 + 4.0 x6 = -6.0

2.0 x1 + 4.0 x2 + 4.0 x3 + 4.0 x4 + 5.0 x5 – 4.0 x6 = -2.0

``````clear all;
close all;

a = [-2.0,5.0,1.0,3.0,4.0,-1.0;2.0,-1.0,-5.0,-2.0,6.0,4.0;-1.0,6.0,-4.0,-5.0,3.0,-1.0;4.0,3.0,-6.0,-5.0,-2.0,-2.0;-3.0,6.0,4.0,2.0,-6.0,4.0;2.0,4.0,4.0,4.0,5.0,-4.0];
b = [0.0;1.0;-6.0;10.0;-6.0;-2.0];
eq = linsolve(a,b);
fprintf("Anwer Of Simultaneous Equations For X = \n");
disp(eq);``````

Output