0% found this document useful (0 votes)
44 views9 pages

ModStat PSet 1

This document contains 6 parts that demonstrate various MATLAB functions and calculations: 1) Basic calculations and operations 2) Defining variables and additional calculations 3) A function to convert temperatures between Fahrenheit and Kelvin 4) Financial planning calculations and functions 5) A function for a mass balance calculation 6) Functions to calculate Collatz sequences and find the maximum sequence length

Uploaded by

KravishIQIce
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)
44 views9 pages

ModStat PSet 1

This document contains 6 parts that demonstrate various MATLAB functions and calculations: 1) Basic calculations and operations 2) Defining variables and additional calculations 3) A function to convert temperatures between Fahrenheit and Kelvin 4) Financial planning calculations and functions 5) A function for a mass balance calculation 6) Functions to calculate Collatz sequences and find the maximum sequence length

Uploaded by

KravishIQIce
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/ 9

1.

Calculations with MATLAB


Part 1
>> 15*(10^(1/2) + 3.7^2)/(log10(1365) + 1.9)
ans =
50.2041
>> ((2.5^3)*(16 - 216/22))/(1.7^4 + 14) + 2050^(1/4)
ans =
11.0501
Part 2
>> x = 8.3;,y = 2.4;
>> x^2 + y^2 - (x^2)/(y^2)
ans =
62.6899
>> (x*y)^(0.5) - (x+y)^(0.5) + ((x-y)/(x-2*y))^2 - (x/y)^(0.5)
ans =
2.1741
>> x = (12/180 * pi);
Part 3
>> tan(4*x) == (4*tan(x) - 4*tan(x)^3)/(1 - 6*tan(x)^2 + tan(x)^4)
ans =
1
>> sin(x)^3 == 0.25*(3*sin(x) - sin(3*x))
ans =
0
>> sin(x)^3
ans =
0.0090
>> 0.25*(3*sin(x) - sin(3*x))
ans =
0.0090

Part 4
>> q = 2*pi*300*401*(100-20)/log(5/3)
q =
1.1838e+08

2. Finding a Function

floor is used to round down to the nearest integer.


while loops until a specified condition is met.
if is used to set a condition.

3. Temperature Conversion

function [tempK] = FtoK(tempF)


tempK = (tempF + 459.67)*(5/9);
end
>> FtoK(32)
ans =
273.1500
>> FtoK(100)
ans =
310.9278

4. Financial planning
(a)
>> format BANK
>> 1000*1.07^(25)
ans =
5427.43
(b)
function [amt] = partb(years)
format BANK;
amt = 0;
count = 1;
while count <= years
amt = amt + 1000;
amt = amt * 1.07;
count = count + 1;
end
end

>> partb(40)
ans =
213609.57
(c)
Case 1: Save $1000/yr for 10 years. Interest for last 30 years.
>> partb(10)
ans =
14783.60
>> ans*1.07^(30)
ans =
112536.53
Case 2: Nothing for 10 years, then $1000/year for 30 years.
>> partb(30)
ans =
101073.04

(d)
Case 1:
function [acct] = partd1(years)
acct = 5000000;
format BANK;
count = 1;
gains = 0;
while count <= years
acct = acct - 200000;
acct = acct * 1.1;
count = count + 1;
gains = gains + 1;
if gains == 4
acct = acct - 200000;
acct = acct * 0.96;
count = count + 1;
end
end
end

>> partd1(20)
ans =
17469934.03
Case 2:
function [acct] = partd2(years)
acct = 5000000;
format BANK;
count = 1;
gains = 0;
while count <= years
acct = acct - 250000;
acct = acct * 1.1;
count = count + 1;
gains = gains + 1;
if gains == 4
acct = acct * 0.96;
count = count + 1;
end
end
end

>> partd2(20)
ans =
15500866.24

5. Mass Balance

function [weight_fraction_strep_in_solvent] = StrepOutputConvert(water_in,


solvent_in)
%1 L = 0.001 cm^3
strep_in = 10 * water_in; %g/hr = g/L * L/hr
strep_out = 0.2 * water_in; %g/hr = g/L * L/hr
strep_extract = strep_in - strep_out; %g/hr
solvent_massflowout = solvent_in * 0.6 * 1000;%g/hr = L/hr * g/cm3 * cm3/L
weight_fraction_strep_in_solvent = strep_extract / solvent_massflowout; %g
strep/g solvent
end

6. Collatz Sequence
(a)
function [length] = collatz(numb)
a = [numb];
count = 2;
while numb ~= 1
if mod(numb,2) == 0
a(count) = numb/2;
numb = a(count);
count = count + 1;
else
a(count) = (numb*3) + 1;
numb = a(count);
count = count + 1;
end
end
length = count - 2;
end

(b)

(c)
>> collatz(4)
ans =
2.00

>> collatz(47)
ans =
104.00

>> collatz(92)
ans =
17.00
(d)

function [max_count,max] = maxcollatz(numb1,numb2)


count = numb1;
max = 0;
while count <= numb2
max_pot = collatz(count);
if max_pot > max
max = max_pot;
max_count = count;
else
count = count + 1;
end
end
end

>> [number,length] = maxcollatz(1,1000)


number =
871
length =
178

You might also like