% EXERCISE 1: Make the equation
function y = YenX(x)
y = ((-0.2.*x.^3) + (7*x.^2)).* exp(-0.3.*x);
>> YenX(-1.5)
ans =
25.7595
>> YenX(5)
ans =
33.4695
% (b)Use the function to make a plot of the function for -2 <= x <= 6
x = -2:0.1:6;
for i = 1:1:length(x)
a = x(i);
y(i) = YenX(a)
end
plot(y,x)
xlabel('X')
ylabel('Y )
% EXERCISE 2: Convert gal/mi to L/km
function Lkm = LkmtoGal(gmi)
Lkm = (gmi .* 2.3521);
fprintf('%.2f gal/mi are %.2f L/km', gmi, Lkm)
>> LkmtoGal(5)
5.00 gal/mi are 11.76 L/km
ans =
11.7605
>> LkmtoGal(5.8)
5.80 gal/mi are 13.64 L/km
ans =
13.6422
% Exercice 3: Expression p
function p = expressionP(c,d,x)
p = ((c.*x)+(2.*d))./((c.*x)-d);
% Exercice 3: Expression q
function q = expressionQ(x,y,z)
q = 2 * log10(x) + cos(pi) + abs((y.^2) - (z.^2)) + sqrt(5 .* y .* z);
% Evaluate P with c=1, d=2 and x=4
c1 = 1;
d1 = 2;
x1 = 4;
result1 = expressionP(c1, d1, x1);
fprintf('p is equal to %.2f, when c is %.2f, d is %.2f, and x is %.2f', result1,
c1, d1, x1)
% Evaluate P whith c=5, d=10 and x=4
c2 = 5;
d2 = 10;
x2 = 4;
result2 = expressionP(c2, d2, x2);
fprintf('\np is equal to %.2f, when c is %.2f, d is %.2f, and x is %.2f',
result2, c2, d2, x2)
% Evaluate P with c=3, d=20 and x=1
c3 = 3;
d3 = 20;
x3 = 1;
result3 = expressionP(c3, d3, x3);
fprintf('\np is equal to %.2f, when c is %.2f, d is %.2f, and x is %.2f',
result3, c3, d3, x3)
% Evaluate q with x=2, y=4 and z=3
x_1 = 2;
y1 = 4;
z1 = 3;
res1 = expressionQ(x_1, y1, z1);
fprintf('\n\nq is equal to %.2f, when x is %.2f, y is %.2f, and z is %.2f',
res1, x_1, y1, z1)
% Evaluate q with x=10, y=5 and z=9
x_2 = 10;
y2 = 5;
z2 = 9;
res2 = expressionQ(x_2, y2, z2);
fprintf('\nq is equal to %.2f, when x is %.2f, y is %.2f, and z is %.2f', res2,
x_2, y2, z2)
% Evaluate q with x=25, y=-2 and z=-1.5
x_3 = 25;
y3 = -2;
z3 = -1.5;
res3 = expressionQ(x_3, y3, z3);
fprintf('\nq is equal to %.2f, when x is %.2f, y is %.2f, and z is %.2f', res3,
x_3, y3, z3)
>> Expresions_Evaluateing_2_noviembre_2023
p is equal to 4.00, when c is 1.00, d is 2.00, and x is 4.00
p is equal to 4.00, when c is 5.00, d is 10.00, and x is 4.00
p is equal to -2.53, when c is 3.00, d is 20.00, and x is 1.00
q is equal to 14.35, when x is 2.00, y is 4.00, and z is 3.00
q is equal to 72.00, when x is 10.00, y is 5.00, and z is 9.00
q is equal to 7.42, when x is 25.00, y is -2.00, and z is -1.50
% Exercice 4: Frequency of oscillation
function f = FrecuOsc(c)
f = sqrt((1./(0.01.*c))-((100.^2)./(4.*c.^2)));
% Values for c
c = 0.1:0.1:1;
fprintf('The inductance is 0.01 mH\n')
fprintf('The resistence is 100 ohms\n')
fprintf('The Frequenncy of ocillation is:')
FrecuOsc(c)
>> FrecuencyOscillation_2_noviembre_2023
The inductance is 0.01 mH
The resistence is 100 ohms
The Frequenncy of ocillation is:
ans =
1.0e+02 *
Columns 1 through 6
0.0000 + 4.9900i 0.0000 + 2.4900i 0.0000 + 1.6566i 0.0000 + 1.2400i
0.0000 + 0.9899i 0.0000 + 0.8233i
Columns 7 through 10
0.0000 + 0.7042i 0.0000 + 0.6149i 0.0000 + 0.5455i 0.0000 + 0.4899i