1 / 6100%
Problem Set 05
Becca Arevalo 10/30/23
Problem 4.21
Problem Statement
Create a MATLAB function fxy to evaluate the function f(x,y)
function:
function result = fxy(x,y)
if (x >= 0) && (y >= 0)
result = x + y;
elseif (x >= 0) && (y <= 0)
result = x - y;
elseif (x < 0) && (y >= 0)
result = -(x^2)*y;
elseif (x < 0) && (y < 0)
result = -(x^2)*(y^2);
end
end
Intitialize variables
clc, clear, close all
t_1=[2, 4];
t_2=[3, -5];
t_3=[-4, 6];
t_4=[-5,-7];
calculations
funtion_t_1=fxy(t_1(1),t_1(2));
funtion_t_2=fxy(t_2(1),t_2(2));
funtion_t_3=fxy(t_3(1),t_3(2));
funtion_t_4=fxy(t_4(1),t_4(2));
expect_1=2+4;
expect_2=3-(-5);
expect_3=((-4)^2)*6;
expect_4=-((-5)^2)*((-7)^2);
1
test=[funtion_t_1 == expect_1, funtion_t_2 == expect_2, funtion_t_3 == expect_3,
funtion_t_4 == expect_4];
Display results
if test == [1 , 1 , 1 , 1]
disp('tests passed')
else
disp('tests not passed')
end
tests not passed
Problem 4.31
Problem statement
Vs(t)=3e^(-t/3) * sin(pi*t)
Intitialize variables
clc, clear, close all
t= [0:0.01:10];
supply1=3.*(exp(-(t./3)));
supply2=sin(pi.*t);
supply_voltage=supply1.*supply2;
voltage1=[];
voltage2=[];
calculations
for lt=1:length(t)
if supply_voltage(lt) > 0
voltage1(lt)=supply_voltage(lt);
elseif supply_voltage(lt) <= 0
voltage1(lt)=0;
end
end
for lt=1:length(t)
if supply_voltage(lt) > 0.6
voltage2(lt)=supply_voltage(lt);
elseif supply_voltage(lt) <= 0.6
voltage2(lt)=0;
end
end
display resuslts
figure
grid minor
hold on
2
plot(t, voltage1)
title ('Diode Voltage1')
xlabel('time (s)'), ylabel('voltage (V)')
ylim([-0.5, 3])
figure
grid minor
hold on
plot(t, voltage2)
title ('Diode Voltage2')
xlabel('time (s)'), ylabel('voltage (V)')
ylim([-0.5, 3])
3
Problem 4.38
Problem Presentation
One bank pays 5.5% per annual interest, while a second pays 4.5%annual interest. Determine how much
longer it will tak to accumulate at least $50,000 in the second bank account if you deposit $1,000 intitially and
$1,000 at the end of each year.
balancea=(balancea*(1+(pair/100)))+deposita
balanceb=(balanceb*(1+(pair/100)))+depositb
Intitialize variables
balance_a=1000;
balance_b=1000;
pair_a=5.5;
pair_b=4.5;
deposit_a=1000;
deposit_b=1000;
years_a=0;
years_b=0;
total=50000;
calculations
while balance_a <= total
balance_a=(balance_a*(1+pair_a/100))+deposit_a;
4
years_a=years_a+1;
end
while balance_b <=total
balance_b=(balance_b*(1+pair_b/100))+deposit_b;
years_b=years_b+1;
end
time=years_b-years_a %gives the difference in time when balance b
time = 2
display results
fprintf('The time it takes for the balance in the bank a to reach 50,000 dollars is
%0.0f years',years_a)
The time it takes for the balance in the bank a to reach 50,000 dollars is 24 years
fprintf('The time it takes for the balance in the bank b to reach 50,000 dollars is
%0.0f years',years_b)
The time it takes for the balance in the bank b to reach 50,000 dollars is 26 years
fprintf('Balance b will take %0.0f years more than balance a to reach 50,000
dollars', time)
Balance b will take 2 years more than balance a to reach 50,000 dollars
Problem 4.46
Problem Statement
Materials u
metal on metal .20
wood on wood .35
metal on wood .40
rubber on concrete .70
To start a weight moving on a horizonal surface, you must push with F force. F=uW. Write a MATLAB program
to compute force F.
Intitialize variables
clc, clear close all
mu=[.20, .35, .40, .70]; % metal on metal, wood on wood, metal on wood, rubber on
concrete
Calculations
menu = menu('choose','metal on metal', 'wood on wood', 'rubber on conrete');
weight= input('enter a number:');
switch menu
case 1
5
f=weight*mu(1)
case 2
f=weight*mu(2)
case 3
f=weight*mu(3)
case 4
f=weight*mu(4)
end
f = 20
Display results
fprintf('The force of material with weight 100 and a static coefficient of friction
.2 for metal on metal is moved horrizontally is 20')
The force of material with weight 100 and a static coefficient of friction .2 for metal on metal is moved horrizontally is 20
6
Students also viewed