0% found this document useful (0 votes)
9 views7 pages

MATLAB Scripts for Mathematical Calculations

The document contains various scripts (H5B1, H5B2, H5B3, H5C1, H5C2, H5C3) that perform mathematical calculations based on user inputs. Each script includes a description of its functionality, sample results, and the output generated for specific input values. The results demonstrate the calculations of products, patterns, cosine values, factorial digits, sequences, and iterative square roots.

Uploaded by

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

MATLAB Scripts for Mathematical Calculations

The document contains various scripts (H5B1, H5B2, H5B3, H5C1, H5C2, H5C3) that perform mathematical calculations based on user inputs. Each script includes a description of its functionality, sample results, and the output generated for specific input values. The results demonstrate the calculations of products, patterns, cosine values, factorial digits, sequences, and iterative square roots.

Uploaded by

9gfysnvwzg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

A1: I read it

A2: I read it

A3: I read it

A4:

t1 = 0.000395300000000,

t2 = 0.024320300000000,

t3 = 36.029877999999997,

t2/t1 = 61.523652921831520,

t3/t2 = 1481.473419324596989

B1:

(a) This is the script:

% Script H5B1

p = input('Input the value of p');

q = input('Input the value of q');

% Perform the calculation of p and q

for k = p:q

for i = p:q

v = k*i;

fprintf('%3i ',v)

end

fprintf('\n');

end

(b): This is the result:

4 6 8 10
6 9 12 15
8 12 16 20
10 15 20 25

B2:

(a) This is the program:

% Script H5B2

% Initializing the parameters

n = input('Input the value of n:');

% Perform through the give value

for i = 1:n

for k = 1:n

if i == 1 || k == 1 || i == k || i == n || k == n

fprintf('*')

else

fprintf(' ')

end

end

fprintf('\n')

end

(b) This is the result:

*****
** *
***
* **
*****
B3:

(a) This is the program:

% Script H5B3

% Initializing the parameters

M = input('Input the value of M');

pb = 1;

qb = 1;

% Perform the calculation

for p = 1:M

for q = 1:M

if cos(q+sqrt(p)) < cos(qb+sqrt(pb))

pb = p;

qb = q;

end

end

end

% Display the result

fprintf('The pb is %i, the qb is %i, the cos(qb+sqrt(qb) is %.15f', pb, qb, cos(qb+sqrt(qb)))

(b) This is the result

When M is 10^1:

The pb is 2, the qb is 8, the cos(qb+sqrt(qb) is -0.999944197262261

When M is 10^2:

The pb is 43, the qb is 28, the cos(qb+sqrt(qb) is -0.999999996746564

When M is 10^3:
The pb is 665, the qb is 147, the cos(qb+sqrt(qb) is -0.999999999997938

When M is 10^4:

The pb is 415, the qb is 1541, the cos(qb+sqrt(qb) is -0.999999999999999

C1:

(a) This is the program:

% Script H5C1

% Initialize the parameter

M = input('Input the value of M');

f = zeros(M,1);

f(1) = 1;

n = 1;

% Perform through the given parameter

while n < M

n = n+1;

f(n) = f(n-1)*n;

end

val = floor(log(f(n))/log(10))+1;

% Display the program

fprintf('When M = %i, the value of the given formula is %i', M, val)

(b) This is the result:

When M = 3, the value of the given formula is 1, number of digits needed for M! is 1

When M = 4, the value of the given formula is 2, number of digits needed for M! is 2

When M = 5, the value of the given formula is 3, number of digits needed for M! is 3

When M = 6, the value of the given formula is 3, number of digits needed for M! is 3

When M = 7, the value of the given formula is 4, number of digits needed for M! is 4
When M = 8, the value of the given formula is 5, number of digits needed for M! is 5

When M = 9, the value of the given formula is 6, number of digits needed for M! is 6

When M = 10, the value of the given formula is 7, number of digits needed for M! is 7

C2:

(a) This is the program:

% Script H5C2

% Initializing the parameters

n = input('Input the value of n:');

a = zeros(n,1);

a(1) = 3;

a(2) = 5;

a(3) = 9;

% Calculate the sequence

for i = 4:n

a(i) = a(i) + 6*a(i-1)-11*a(i-2)+6*a(i-3);

end

% Display the result

fprintf('When n is %i, an is %i',n,a(i))

(b) This is the result:

When n is 10, an is 1025

When n is 20, an is 1048577

When n is 30, an is 1073741825


C3:

(a) This is the program:

% Script H5C3

% Initializing the parameters

m = input('Input the value of m');

n = input('Input the value of n');

t = zeros(n,1);

t(1) = sqrt(m);

t(2) = sqrt(m-sqrt(m));

% Calculation base on the given values

for i = 3:n

t(i) = sqrt(m-sqrt(m+t(i-2)));

end

% Display the result

fprintf('When m is %i, when n is %i, tn is %.15f', m, n, t(i))

(b) This is the result:

When m is 2, when n is 10, tn is 0.618617520624537

When m is 2, when n is 20, tn is 0.618033418866108

When m is 2, when n is 50, tn is 0.618033988749895

When m is 7, when n is 10, tn is 2.000000260896433

When m is 7, when n is 20, tn is 1.999999999999967

When m is 7, when n is 50, tn is 2.000000000000000

You might also like