1 / 5100%
1
Problem Set 05
Authored by Kayla Ufer Authored on 3/9/2022
Problem 4.21
Initialize Variables
Display Results
When f(3,3) exists, the function value output is 9
When f(3,-3) exists, the function value output is 27
When f(-3,3) exists, the function value output is 27
When f(-3,-3) exists, the function value output is 81
Problem 4.28
Initialize Variables for Part A
Perform Calculations for Part A
%Display value for case 3
fprintf('When f(-3,-3) exists, the function value output is %1.0f', val4)
%Display calculations for case 1
fprintf('When f(3,-3) exists, the function value output is %1.0f', val2)
clear,clc,close all
val1 = fxy(3,3); %input values for case 1 from function
val2 = fxy(3,-3); %input values for case 2 from fucntion
val3 = fxy(-3,3);%input values for case 3 from function
val4 = fxy(-3,-3); %input values for 4 from function
fprintf('When f(3,3) exists, the function value output is %1.0f', val1)
%Display value for case 2
fprintf('When f(-3,3) exists, the function value output is %1.0f', val3)
%Display value for case 4
clc, clear, close all
t = 0:0.01:10; %Initialize time variable, seconds[s]
vs = 3.*exp((-t)/3).*sin(pi.*(t)); %Initialize supply voltage function
vs_b = 3.*exp((-t)/3).*sin(pi.*(t)); %Initialize supply voltage function
vl = zeros(length(t)); %Initliazie the voltage output of the iode
vl_b = zeros(length(t)); %Initliazie the voltage output of the iode
for i = 1:length(t) %Find i from 1 through length of t time in seconds
2
Perform Calculations for Part B
for i = 1:length(t) %Initliaze i for case 2
if vs_b(i) > 0.6 %Create condition for all vs values greater than .6
vl_b(i) = vs_b(i)-0.6; %Satisfy Condition for above statement
elseif vs_b(i) <= 0.6 %Create secondary condition counter to the previous condition
vl_b(i) = 0; %Satisfy the second condition
end %End if loop
end %End for loop
Plot Data
if vs(i) > 0 %Create condition for vs greater than 0
vl(i) = vs(i); %Satisfy if conditionby setting vs equal to vl
elseif vs(i) <= 0 %Set condition for all value less than or equal to zero
vl = 0; %Satisfy condition for above statement
end %End loop
end %End loop
figure
hold on
plot(t,vl), grid minor %Plot Data for Part A
title('Time vs. Voltage') %Create title for part A
xlabel("Time"), ylabel("Voltage") %Label x and y axis
hold off
3
Problem 4.34
Initialize Variables
Calculate Values
figure
hold on
plot(t,vl_b), grid minor %Plot Data for Part B
title('Time vs. Voltage') %Create Title for Graph B
xlabel("Time"), ylabel('Voltage') %Label x and y axis
hold off
clc, clear, close all
rate1 = 0.055; %Interest of bank 1
rate2 = 0.045; %Interest of bank 2
balance1 = 1000; %Interest balance of bank 1 in dollars, $
balance2 = 1000; %Interest balance of bank 2 in dollars, $
year1 = 0; %Life in years
year2 = 0; %Life in years
while balance1 < 50000 %Initiate while loop
balance1 = balance1 * (1+rate1); %Add interest rate to the balance of bank 1
4
2
Display Results
fprintf('The number of year that it took to reach $50,000 for Bank 1 was %2.0f',year1)
The number of year that it took to reach $50,000 for Bank 1 was 24
%Display results for the year that it took to reach 50,000 dollars
fprintf('The number of year that it took to reach $50,000 for Bank 2 was %2.0f',year2)
The number of year that it took to reach $50,000 for Bank 2 was 26
The difference between these two year values is 2
Problem 4.42
Initialize Variables
Input Values
W = inputdlg('Enter the weight: '); %Ask for the weight
Weight = str2num(W{1}); %Convert the string input to a numerical value
choice = menu('Choose Material:', 'Metal on Metal', 'Wood on Wood', 'Metal on Wood', 'R
choice = 4
Display Results
%Calculate and display the results between the 2 years
balance1 = balance1 + 1000; %Add initial payment to balance 1
year1 = year1 + 1; %Incremental year increase
while balance2 < 50000; %Initiare while loop
balance2 = balance2 * (1+rate2); %Add interest rate to the balance of bank
balance2 = balance2 + 1000; %Add initial payment to balance 2
year2 = year2 + 1; %Incremental year increase
end
end
%Display results for the year that it took to reach 50,000 dollars
fprintf('The difference between these two year values is %1.0f', year2-year1)
clc, clear, close all
met_met = 0.2; %metal on metal friction coefficiant
wood_wood = 0.35; %wood on wood friction coefficiant
met_wood = 0.4; %metal on wood friction coefficiant
rub_con = 0.7; %rubber on concrete friction coefficiant
switch choice
case 1
friction = Weight*met_met %computes the fricion force of metal on metal
case 2
friction = Weight*wood_wood %computes the friction force of wood on wood
5
friction = 5.3886e+07
Display Results
The force required to move your material is 53885684
case 3
friction = Weight*met_wood %computes the friction force of metal on wood
case 4
friction = Weight*rub_con %computes the friction force of rubber on concrete
end
fprintf('The force required to move your material is %2.0f', friction)
function f = fxy(x,y) %define function
%[fxy] = function value of x and y
if x >= 0 && y >= 0 %condition for x and y
f = x*y; %resultant of x and y condition
elseif x >= 0 && y <= 0 %conditional statement for x and y
f = x*y^2; %resultant of x and y condition
elseif x < 0 && y >= 0 %conditional x and y statement
f = x^2*y; %resultant of x and y
elseif x < 0 && y < 0 %conditional x and y statement
f = x^2*y^2; %resultant of x and y
end %end section
end %end section
Students also viewed