[go: up one dir, main page]

0% found this document useful (0 votes)
28 views31 pages

CMP 1

The document contains various computational exercises in MATLAB related to programming and mathematical functions. It includes examples of function definitions, evaluations, and plotting, along with calculations for power generation, polynomial roots, and trigonometric functions. The exercises cover a range of topics suitable for a Mechanical Engineering curriculum.

Uploaded by

cynosure
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)
28 views31 pages

CMP 1

The document contains various computational exercises in MATLAB related to programming and mathematical functions. It includes examples of function definitions, evaluations, and plotting, along with calculations for power generation, polynomial roots, and trigonometric functions. The exercises cover a range of topics suitable for a Mechanical Engineering curriculum.

Uploaded by

cynosure
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/ 31

Name: Yashashri Haresh Chaudhari

MIS Number: 642310021


TY BTech Mechanical Engineering
Subject: Computational Methods of Programming
1. Estimate the following using command prompt.

>> f = 3^2-((5+4)/2)+6*3

f=

22.5000

>> % Define the function


f = @(x) 3*x.^3 + 5*x + 50;

% Define the values of x


x_values = [0, 0.5, 10, 100];

% Evaluate the function for each x


results = f(x_values);

% Display the results


disp('Function values:');
disp(results);

Function values:
1.0e+06 *

0.0001 0.0001 0.0031 3.0006


>> % Define the function


f = @(x) x.^2 + 5 .* sin(x) + exp(cos(x));

% Define the values of x


x_values = [5, 10, 100];

% Evaluate the function for each x


results = f(x_values);

% Display the results


disp('Function values:');
disp(results);
Function values:
1.0e+03 *

0.0215 0.0977 9.9998

>> x = 5; % Value of x
y = 10; % Value of y
f = 5 * x + 10 * y; % Evaluate the function
disp(f); % Display the result
125

% Assign values to variables


x = 1;
y = 5;
z = 6;

% Evaluate the function


f = x^2 + 5*x*y + 10*x*y*z + x*y^2 + sin(x + y)/z;

% Display the result


disp(f);
350.9534

% Define the values of x in degrees


x_degrees = [0, 90, 45];

% Convert degrees to radians (since MATLAB trigonometric functions use


radians)
x_radians = deg2rad(x_degrees);

% Evaluate the function


f = sin(x_radians).^2 + cos(x_radians).^2;

% Display the results


disp('Function values:');
disp(f);
Function values:
1 1 1

% Assign values to x and y


x = 5.450;
y = 45.670;

% Evaluate the function


f = tan(x) + sin(x) + cos(2*x*y/x^2) + (sec^2)*( x/y);

% Display the result


disp('Function value:');
disp(f);

>> % Assign the value of x


x = 5;

%Assign the value of y


y=4.552;

% Evaluate the function


f = sin(x) + cos(x) * log2(x/2);

% Display the result


disp('Function value:');
disp(f);
Function value:
-0.5839
2. Determine the value of the expression a(b + c(c + d))a, where a = 2, b = 3, c
= −4 and d = −3.

% Assign values
a = 2;
b = 3;
c = -4;
d = -3;

% Compute the expression


result = a * (b + c * (c + d)) * a;

% Display the result


disp(result)
124

3.

>> % Given values


a = 3;
b = 5;
c = -3;
w = 1; % Assuming w is 1 since it's not provided.

% Expression
result = (b - (a / (b + (b + (a / (w * a))))));
% Display the result
disp(result);
4.7273

4. Estimate Power generated by Engine from experimental readings Torque =


12.67 Nm, Speed of Engine = 1534 rpm. Hint use P = ( 2πNT)/60.

>> % Given values


N = 1534; % Speed of engine in RPM
T = 12.67; % Torque in Nm

% Calculate power using the formula


P = (2 * pi * N * T) / 60;

% Display the result


disp(['Power generated by the engine: ', num2str(P), ' Watts']);
Power generated by the engine: 2035.3101 Watts

5. Set up a vector x which contains the values from zero to one in steps of one
tenth.

>> % Create vector x from 0 to 1 in steps of 0.1


x = 0:0.1:1;

% Display the vector


disp(x);
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000
0.8000 0.9000 1.0000

6. Construct the polynomial y = (x + 2)2 (x 3 + 1) for values of x from minus


one to one in steps of 0.1.

>> % Create vector x from -1 to 1 in steps of 0.1


x = -1:0.1:1;

% Compute y using the polynomial expression


y = (x + 2).^2 .* (x.^3 + 1);

% Display the values of y


disp(y);
Columns 1 through 12

0 0.3279 0.7027 1.1103 1.5366 1.9688 2.3962 2.8120


3.2141 3.6064 4.0000 4.4144

Columns 13 through 21

4.8787 5.4328 6.1286 7.0312 8.2202 9.7905 11.8541 14.5409


18.0000

7. Construct the function y = x^2/x^3+1 for values of x from one to two in


steps of 0.01.

>> % Create vector x from 1 to 2 in steps of 0.01


x = 1:0.01:2;

% Compute y using the given function


y = (x.^2) ./ (x.^3 + 1);

% Display the values of y


disp(y);
Columns 1 through 12

0.5000 0.5024 0.5048 0.5069 0.5090 0.5110 0.5128 0.5146


0.5162 0.5177 0.5191 0.5204

Columns 13 through 24
0.5216 0.5227 0.5237 0.5246 0.5254 0.5262 0.5268 0.5274
0.5279 0.5283 0.5286 0.5288

Columns 25 through 36

0.5290 0.5291 0.5291 0.5291 0.5290 0.5288 0.5286 0.5283


0.5280 0.5276 0.5272 0.5267

Columns 37 through 48

0.5261 0.5255 0.5249 0.5242 0.5235 0.5227 0.5219 0.5211


0.5202 0.5193 0.5184 0.5174

Columns 49 through 60

0.5164 0.5153 0.5143 0.5132 0.5121 0.5109 0.5098 0.5086


0.5074 0.5062 0.5049 0.5036

Columns 61 through 72

0.5024 0.5011 0.4997 0.4984 0.4971 0.4957 0.4943 0.4930


0.4916 0.4902 0.4888 0.4873

Columns 73 through 84

0.4859 0.4845 0.4830 0.4816 0.4801 0.4787 0.4772 0.4757


0.4742 0.4728 0.4713 0.4698

Columns 85 through 96

0.4683 0.4668 0.4653 0.4638 0.4623 0.4608 0.4593 0.4579


0.4564 0.4549 0.4534 0.4519

Columns 97 through 101

0.4504 0.4489 0.4474 0.4459 0.4444


8. Construct the function y(x) = sin(x * cos(x) / (x^2 + 3x + 1)) for values of x
from one to three in steps of 0.02.

>> % Create vector x from 1 to 3 in steps of 0.02


x = 1:0.02:3;

% Compute y(x) using the given function


y = sin((x .* cos(x)) ./ (x.^2 + 3*x + 1));

% Display the values of y


disp(y);
Columns 1 through 12

0.1079 0.1045 0.1010 0.0976 0.0940 0.0904 0.0868 0.0831


0.0794 0.0757 0.0719 0.0681

Columns 13 through 24

0.0643 0.0605 0.0566 0.0527 0.0489 0.0450 0.0411 0.0371


0.0332 0.0293 0.0254 0.0215

Columns 25 through 36

0.0176 0.0137 0.0098 0.0059 0.0021 -0.0018 -0.0056 -0.0094


-0.0132 -0.0169 -0.0207 -0.0244

Columns 37 through 48

-0.0280 -0.0317 -0.0353 -0.0389 -0.0424 -0.0459 -0.0494 -0.0528


-0.0562 -0.0595 -0.0628 -0.0661
Columns 49 through 60

-0.0693 -0.0725 -0.0756 -0.0787 -0.0817 -0.0846 -0.0876 -0.0904


-0.0932 -0.0960 -0.0987 -0.1013

Columns 61 through 72

-0.1039 -0.1064 -0.1089 -0.1113 -0.1136 -0.1159 -0.1181 -0.1203


-0.1224 -0.1245 -0.1264 -0.1283

Columns 73 through 84

-0.1302 -0.1320 -0.1337 -0.1354 -0.1370 -0.1385 -0.1400 -0.1414


-0.1427 -0.1440 -0.1452 -0.1463

Columns 85 through 96

-0.1474 -0.1484 -0.1493 -0.1502 -0.1510 -0.1518 -0.1524 -0.1530


-0.1536 -0.1541 -0.1545 -0.1549

Columns 97 through 101

-0.1551 -0.1554 -0.1555 -0.1556 -0.1557

9. Plot the polynomial y = x 4 + x2 − 1 between x = −2 and x = 2 (using fifty


points).

>> % Create vector x with 50 points between -2 and 2


x = linspace(-2, 2, 50);

% Compute y using the given polynomial


y = x.^4 + x.^2 - 1;

% Plot the polynomial


plot(x, y);

% Add title and labels to the plot


title('Plot of y = x^4 + x^2 - 1');
xlabel('x');
ylabel('y');

% Display grid for better visualization


grid on;

10.Find the roots of the polynomial y = x 3 − 3x2 + 2x using the command


roots.

>> % Define the coefficients of the polynomial


coefficients = [1 -3 2 0];

% Find the roots of the polynomial


r = roots(coefficients);

% Display the roots


disp('The roots of the polynomial are:');
disp(r);
The roots of the polynomial are:
0
2
1

11.Construct the function f(x)=x2+2 on the set of points x = 0 to 2 in steps of


0.1 and give the value of f(x) at x = 0, x = 1 and x = 2. The code to construct
the function is:

>> % Create vector x from 0 to 2 in steps of 0.1


x = 0:0.1:2;

% Compute f(x) = x^2 + 2


f_x = x.^2 + 2;

% Display the values of f(x) at x = 0, x = 1, and x = 2


disp('f(x) at x = 0:');
disp(f_x(1)); % f(0)

disp('f(x) at x = 1:');
disp(f_x(11)); % f(1) (index 11 corresponds to x = 1)

disp('f(x) at x = 2:');
disp(f_x(21)); % f(2) (index 21 corresponds to x = 2)

% Optionally, plot the function


plot(x, f_x);
title('Plot of f(x) = x^2 + 2');
xlabel('x');
ylabel('f(x)');
grid on;
f(x) at x = 0:
2

f(x) at x = 1:
3

f(x) at x = 2:
6

12.Calculate the values of the following expressions

1)

% Given value of x
x = 1.3;

% Compute the polynomial p(x) = x^2 + 3x + 1


p_x = x^2 + 3*x + 1;

% Display the result


disp(['The value of p(x) at x = 1.3 is: ', num2str(p_x)]);
The value of p(x) at x = 1.3 is: 6.59

2)
>> % Given value of x in degrees
x_deg = 30;

% Convert degrees to radians


x_rad = deg2rad(x_deg);

% Compute y(x) = sin(x) at x = 30 degrees


y_x = sin(x_rad);

% Display the result


disp(['The value of y(x) at x = 30 degrees is: ', num2str(y_x)]);
The value of y(x) at x = 30 degrees is: 0.5

3)
>> % Given value of x
x = 1;

% Compute f(x) = tan^(-1)(x) at x = 1


f_x = atan(x);

% Display the result


disp(['The value of f(x) at x = 1 is: ', num2str(f_x)]);
The value of f(x) at x = 1 is: 0.7854

4)

>> % Given value of x


x = sqrt(3)/2;

% Compute g(x) = sin(acos(x)) at x = sqrt(3)/2


g_x = sin(acos(x));

% Display the result


disp(['The value of g(x) at x = sqrt(3)/2 is: ', num2str(g_x)]);
The value of g(x) at x = sqrt(3)/2 is: 0.5

13.Calculate the value of the function y(x) = |x| sin x 2 for values of x = π/3 and
π/6 (use the MATLAB command abs(x) to calculate |x|).

>> % Given values of x


x1 = pi/3;
x2 = pi/6;

% Compute y(x) = |x| * sin(x^2) for x = pi/3


y1 = abs(x1) * sin(x1^2);

% Compute y(x) = |x| * sin(x^2) for x = pi/6


y2 = abs(x2) * sin(x2^2);

% Display the results


disp(['The value of y(x) at x = pi/3 is: ', num2str(y1)]);
disp(['The value of y(x) at x = pi/6 is: ', num2str(y2)]);
The value of y(x) at x = pi/3 is: 0.93166
The value of y(x) at x = pi/6 is: 0.14176

14.Calculate the quantities sin(π/2), cos(π/3), tan 60◦ and ln(x +√x2 + 1) where
x = 1/2 and x = 1. Calculate the expression x/((x2 +1) sin(x)) where x = π/4
and x = π/2.

>> % Given values


x1 = pi/2;
x2 = pi/3;
x3_deg = 60; % Degrees for tan(60°)
x4_1 = 1/2; % For ln(x + sqrt(x^2 + 1)) when x = 1/2
x4_2 = 1; % For ln(x + sqrt(x^2 + 1)) when x = 1
x5_1 = pi/4; % For x/((x^2 + 1) * sin(x)) when x = pi/4
x5_2 = pi/2; % For x/((x^2 + 1) * sin(x)) when x = pi/2

% Calculate the quantities


sin_pi_2 = sin(x1);
cos_pi_3 = cos(x2);
tan_60_deg = tan(deg2rad(x3_deg)); % Convert 60 degrees to radians
ln_x1 = log(x4_1 + sqrt(x4_1^2 + 1)); % When x = 1/2
ln_x2 = log(x4_2 + sqrt(x4_2^2 + 1)); % When x = 1
expr_x1 = x5_1 / ((x5_1^2 + 1) * sin(x5_1)); % When x = pi/4
expr_x2 = x5_2 / ((x5_2^2 + 1) * sin(x5_2)); % When x = pi/2

% Display the results


disp(['sin(π/2) = ', num2str(sin_pi_2)]);
disp(['cos(π/3) = ', num2str(cos_pi_3)]);
disp(['tan(60°) = ', num2str(tan_60_deg)]);
disp(['ln(1/2 + sqrt((1/2)^2 + 1)) = ', num2str(ln_x1)]);
disp(['ln(1 + sqrt(1^2 + 1)) = ', num2str(ln_x2)]);
disp(['Expression for x = π/4: x/((x^2 + 1) * sin(x)) = ', num2str(expr_x1)]);
disp(['Expression for x = π/2: x/((x^2 + 1) * sin(x)) = ', num2str(expr_x2)]);
sin(π/2) = 1
cos(π/3) = 0.5
tan(60°) = 1.7321
ln(1/2 + sqrt((1/2)^2 + 1)) = 0.48121
ln(1 + sqrt(1^2 + 1)) = 0.88137
Expression for x = π/4: x/((x^2 + 1) * sin(x)) = 0.68697
Expression for x = π/2: x/((x^2 + 1) * sin(x)) = 0.45302

15.Explore the use of the functions round, ceil, floor and fix for the values x =
0.3, x = 1/3, x = 0.5, x = 1/2, x = 1.65 and x = −1.34.

 round(x) rounds x to the nearest integer. If x is halfway between two


integers, it rounds to the nearest even integer.
 ceil(x) rounds x towards positive infinity (i.e., rounds up).
 floor(x) rounds x towards negative infinity (i.e., rounds down).
 fix(x) rounds x towards zero (i.e., truncates the decimal part).

>> % Given values


x1 = 0.3;
x2 = 1/3;
x3 = 0.5;
x4 = 1/2;
x5 = 1.65;
x6 = -1.34;

% Apply the functions to each value of x


round_x1 = round(x1);
ceil_x1 = ceil(x1);
floor_x1 = floor(x1);
fix_x1 = fix(x1);

round_x2 = round(x2);
ceil_x2 = ceil(x2);
floor_x2 = floor(x2);
fix_x2 = fix(x2);

round_x3 = round(x3);
ceil_x3 = ceil(x3);
floor_x3 = floor(x3);
fix_x3 = fix(x3);

round_x4 = round(x4);
ceil_x4 = ceil(x4);
floor_x4 = floor(x4);
fix_x4 = fix(x4);

round_x5 = round(x5);
ceil_x5 = ceil(x5);
floor_x5 = floor(x5);
fix_x5 = fix(x5);

round_x6 = round(x6);
ceil_x6 = ceil(x6);
floor_x6 = floor(x6);
fix_x6 = fix(x6);

% Display results
disp('Results for x = 0.3:');
disp(['round(0.3) = ', num2str(round_x1)]);
disp(['ceil(0.3) = ', num2str(ceil_x1)]);
disp(['floor(0.3) = ', num2str(floor_x1)]);
disp(['fix(0.3) = ', num2str(fix_x1)]);

disp('Results for x = 1/3:');


disp(['round(1/3) = ', num2str(round_x2)]);
disp(['ceil(1/3) = ', num2str(ceil_x2)]);
disp(['floor(1/3) = ', num2str(floor_x2)]);
disp(['fix(1/3) = ', num2str(fix_x2)]);

disp('Results for x = 0.5:');


disp(['round(0.5) = ', num2str(round_x3)]);
disp(['ceil(0.5) = ', num2str(ceil_x3)]);
disp(['floor(0.5) = ', num2str(floor_x3)]);
disp(['fix(0.5) = ', num2str(fix_x3)]);

disp('Results for x = 1/2:');


disp(['round(1/2) = ', num2str(round_x4)]);
disp(['ceil(1/2) = ', num2str(ceil_x4)]);
disp(['floor(1/2) = ', num2str(floor_x4)]);
disp(['fix(1/2) = ', num2str(fix_x4)]);

disp('Results for x = 1.65:');


disp(['round(1.65) = ', num2str(round_x5)]);
disp(['ceil(1.65) = ', num2str(ceil_x5)]);
disp(['floor(1.65) = ', num2str(floor_x5)]);
disp(['fix(1.65) = ', num2str(fix_x5)]);

disp('Results for x = -1.34:');


disp(['round(-1.34) = ', num2str(round_x6)]);
disp(['ceil(-1.34) = ', num2str(ceil_x6)]);
disp(['floor(-1.34) = ', num2str(floor_x6)]);
disp(['fix(-1.34) = ', num2str(fix_x6)]);
Results for x = 0.3:
round(0.3) = 0
ceil(0.3) = 1
floor(0.3) = 0
fix(0.3) = 0
Results for x = 1/3:
round(1/3) = 0
ceil(1/3) = 1
floor(1/3) = 0
fix(1/3) = 0
Results for x = 0.5:
round(0.5) = 1
ceil(0.5) = 1
floor(0.5) = 0
fix(0.5) = 0
Results for x = 1/2:
round(1/2) = 1
ceil(1/2) = 1
floor(1/2) = 0
fix(1/2) = 0
Results for x = 1.65:
round(1.65) = 2
ceil(1.65) = 2
floor(1.65) = 1
fix(1.65) = 1
Results for x = -1.34:
round(-1.34) = -1
ceil(-1.34) = -1
floor(-1.34) = -2
fix(-1.34) = -1

16.Compare the MATLAB functions rem(x,y) and mod(x,y) for a variety of


values of x and y (try x = 3, 4, 5 and y = 3, 4,−4, 6).

>> % Define the values of x and y


x_values = [3, 4, 5];
y_values = [3, 4, -4, 6];

% Loop through all combinations of x and y


for x = x_values
for y = y_values
% Calculate rem(x, y) and mod(x, y)
rem_result = rem(x, y);
mod_result = mod(x, y);

% Display the results


disp(['For x = ', num2str(x), ' and y = ', num2str(y), ':']);
disp(['rem(x, y) = ', num2str(rem_result)]);
disp(['mod(x, y) = ', num2str(mod_result)]);
disp(' ');
end
end
For x = 3 and y = 3:
rem(x, y) = 0
mod(x, y) = 0

For x = 3 and y = 4:
rem(x, y) = 3
mod(x, y) = 3

For x = 3 and y = -4:


rem(x, y) = 3
mod(x, y) = -1

For x = 3 and y = 6:
rem(x, y) = 3
mod(x, y) = 3

For x = 4 and y = 3:
rem(x, y) = 1
mod(x, y) = 1

For x = 4 and y = 4:
rem(x, y) = 0
mod(x, y) = 0

For x = 4 and y = -4:


rem(x, y) = 0
mod(x, y) = 0

For x = 4 and y = 6:
rem(x, y) = 4
mod(x, y) = 4

For x = 5 and y = 3:
rem(x, y) = 2
mod(x, y) = 2

For x = 5 and y = 4:
rem(x, y) = 1
mod(x, y) = 1

For x = 5 and y = -4:


rem(x, y) = 1
mod(x, y) = -3

For x = 5 and y = 6:
rem(x, y) = 5
mod(x, y) = 5

17.

>> % Define the range for x from 3 to 5 in steps of 0.01


x = 3:0.01:5;

% Calculate the function y = x / (x + 1/x^2)


y = x ./ (x + 1 ./ x.^2);

% Display the result (optional)


disp('Values of x and corresponding y:');
disp(table(x', y', 'VariableNames', {'x', 'y'}));
Values of x and corresponding y:
x y
____ _______

3 0.96429
3.01 0.96463
3.02 0.96497
3.03 0.9653
3.04 0.96563
3.05 0.96595
3.06 0.96628
3.07 0.96659
3.08 0.96691
3.09 0.96722
3.1 0.96752
3.11 0.96783
3.12 0.96812
3.13 0.96842
3.14 0.96871
3.15 0.969
3.16 0.96928
3.17 0.96956
3.18 0.96984
3.19 0.97012
3.2 0.97039
3.21 0.97065
3.22 0.97092
3.23 0.97118
3.24 0.97144
3.25 0.97169
3.26 0.97195
3.27 0.9722
3.28 0.97244
3.29 0.97269
3.3 0.97293
3.31 0.97316
3.32 0.9734
3.33 0.97363
3.34 0.97386
3.35 0.97409
3.36 0.97431
3.37 0.97454
3.38 0.97476
3.39 0.97497
3.4 0.97519
3.41 0.9754
3.42 0.97561
3.43 0.97582
3.44 0.97602
3.45 0.97623
3.46 0.97643
3.47 0.97663
3.48 0.97682
3.49 0.97702
3.5 0.97721
3.51 0.9774
3.52 0.97759
3.53 0.97777
3.54 0.97796
3.55 0.97814
3.56 0.97832
3.57 0.97849
3.58 0.97867
3.59 0.97884
3.6 0.97902
3.61 0.97919
3.62 0.97936
3.63 0.97952
3.64 0.97969
3.65 0.97985
3.66 0.98001
3.67 0.98017
3.68 0.98033
3.69 0.98049
3.7 0.98064
3.71 0.98079
3.72 0.98094
3.73 0.98109
3.74 0.98124
3.75 0.98139
3.76 0.98154
3.77 0.98168
3.78 0.98182
3.79 0.98196
3.8 0.9821
3.81 0.98224
3.82 0.98238
3.83 0.98251
3.84 0.98265
3.85 0.98278
3.86 0.98291
3.87 0.98304
3.88 0.98317
3.89 0.9833
3.9 0.98342
3.91 0.98355
3.92 0.98367
3.93 0.98379
3.94 0.98391
3.95 0.98403
3.96 0.98415
3.97 0.98427
3.98 0.98439
3.99 0.9845
4 0.98462
4.01 0.98473
4.02 0.98484
4.03 0.98495
4.04 0.98506
4.05 0.98517
4.06 0.98528
4.07 0.98538
4.08 0.98549
4.09 0.98559
4.1 0.9857
4.11 0.9858
4.12 0.9859
4.13 0.986
4.14 0.9861
4.15 0.9862
4.16 0.9863
4.17 0.9864
4.18 0.98649
4.19 0.98659
4.2 0.98668
4.21 0.98678
4.22 0.98687
4.23 0.98696
4.24 0.98705
4.25 0.98714
4.26 0.98723
4.27 0.98732
4.28 0.98741
4.29 0.98749
4.3 0.98758
4.31 0.98766
4.32 0.98775
4.33 0.98783
4.34 0.98791
4.35 0.988
4.36 0.98808
4.37 0.98816
4.38 0.98824
4.39 0.98832
4.4 0.9884
4.41 0.98847
4.42 0.98855
4.43 0.98863
4.44 0.9887
4.45 0.98878
4.46 0.98885
4.47 0.98893
4.48 0.989
4.49 0.98907
4.5 0.98915
4.51 0.98922
4.52 0.98929
4.53 0.98936
4.54 0.98943
4.55 0.9895
4.56 0.98956
4.57 0.98963
4.58 0.9897
4.59 0.98976
4.6 0.98983
4.61 0.9899
4.62 0.98996
4.63 0.99003
4.64 0.99009
4.65 0.99015
4.66 0.99021
4.67 0.99028
4.68 0.99034
4.69 0.9904
4.7 0.99046
4.71 0.99052
4.72 0.99058
4.73 0.99064
4.74 0.9907
4.75 0.99076
4.76 0.99081
4.77 0.99087
4.78 0.99093
4.79 0.99098
4.8 0.99104
4.81 0.99109
4.82 0.99115
4.83 0.9912
4.84 0.99126
4.85 0.99131
4.86 0.99136
4.87 0.99142
4.88 0.99147
4.89 0.99152
4.9 0.99157
4.91 0.99162
4.92 0.99167
4.93 0.99172
4.94 0.99177
4.95 0.99182
4.96 0.99187
4.97 0.99192
4.98 0.99197
4.99 0.99202
5 0.99206

18.

>> % Define the range for x from -2 to -1 in steps of 0.1


x = -2:0.1:-1;

% Calculate the function y = 1/x^3 + 1/x^2 + 3/x


y = (1 ./ x.^3) + (1 ./ x.^2) + (3 ./ x);

% Display the result (optional)


disp('Values of x and corresponding y:');
disp(table(x', y', 'VariableNames', {'x', 'y'}));
Values of x and corresponding y:
x y
____ _______

-2 -1.375
-1.9 -1.4477
-1.8 -1.5295
-1.7 -1.6222
-1.6 -1.7285
-1.5 -1.8519
-1.4 -1.9971
-1.3 -2.1711
-1.2 -2.3843
-1.1 -2.6521
-1 -3
19.Evaluate the functions (For x from 1 to 2 in steps of 0.1)

a)

>> % Define the range for x from 1 to 2 in steps of 0.1


x = 1:0.1:2;

% Calculate the first function y = x^3 + 3x^2 + 1


y1 = x.^3 + 3.*x.^2 + 1;

% Calculate the second function y = sin(x^2)


y2 = sin(x.^2);

% Calculate the third function y = (sin(x))^2


y3 = (sin(x)).^2;

% Display the results


disp('For x from 1 to 2, here are the values of y for each function:');
disp(table(x', y1', y2', y3', 'VariableNames', {'x', 'y1 (x^3 + 3x^2 + 1)',
'y2 (sin(x^2))', 'y3 ((sin(x))^2)'}));
For x from 1 to 2, here are the values of y for each function:
x y1 (x^3 + 3x^2 + 1) y2 (sin(x^2)) y3 ((sin(x))^2)
___ ___________________ _____________
_______________

1 5 0.84147 0.70807
1.1 5.961 0.93562 0.79425
1.2 7.048 0.99146 0.8687
1.3 8.267 0.9929 0.92844
1.4 9.624 0.92521 0.97111
1.5 11.125 0.77807 0.995
1.6 12.776 0.54936 0.99915
1.7 14.583 0.24895 0.9834
1.8 16.552 -0.098249 0.94838
1.9 18.689 -0.45147 0.89548
2 21 -0.7568 0.82682

b)

>> % Define the range for x from 1 to 2 in steps of 0.1


x = 1:0.1:2;

% Calculate the function y = sin(2x) + x * cos(4)


y = sin(2 * x) + x .* cos(4);

% Display the result


disp('Values of x and corresponding y:');
disp(table(x', y', 'VariableNames', {'x', 'y'}));
Values of x and corresponding y:
x y
___ ________

1 0.25565
1.1 0.089488
1.2 -0.10891
1.3 -0.33424
1.4 -0.58011
1.5 -0.83935
1.6 -1.1042
1.7 -1.3667
1.8 -1.6191
1.9 -1.8538
2 -2.0641
c)

>> % Define the range for x from 1 to 2 in steps of 0.1


x = 1:0.1:2;

% First function y = x / (x^2 + 1)


y1 = x ./ (x.^2 + 1);

% Second function y = cos(x) / (1 + sin(x))


y2 = cos(x) ./ (1 + sin(x));

% Third function y = (1 / x) + (x^3 / (x^4 + 5x * sin(x)))


y3 = (1 ./ x) + (x.^3 ./ (x.^4 + 5 .* x .* sin(x)));

% Display the results


disp('Values of x and corresponding y for each function:');
disp(table(x', y1', y2', y3', 'VariableNames', {'x', 'y1 (x / (x^2 + 1))', 'y2
(cos(x) / (1 + sin(x)))', 'y3 ((1 / x) + (x^3 / (x^4 + 5x * sin(x))))'}));
Values of x and corresponding y for each function:
x y1 (x / (x^2 + 1)) y2 (cos(x) / (1 + sin(x))) y3 ((1 / x) +
(x^3 / (x^4 + 5x * sin(x))))
___ __________________ __________________________
__________________________________________

1 0.5 0.29341 1.192


1.1 0.49774 0.23984 1.1182
1.2 0.4918 0.18755 1.0587
1.3 0.48327 0.13623 1.0102
1.4 0.47297 0.085606 0.96979
1.5 0.46154 0.035413 0.93573
1.6 0.44944 -0.014603 0.90651
1.7 0.43702 -0.064692 0.881
1.8 0.42453 -0.11511 0.85832
1.9 0.41215 -0.1661 0.83778
2 0.4 -0.21796 0.81881

You might also like