Open TadashiJei opened 2 weeks ago
% SYSTEM 1 % -24 - 8x = 12y % 1 + (5/9)y = -(7/18)x
% Rearrange to standard form (ax + by = c): % 8x + 12y = -24 % (7/18)x + (5/9)y = -1
% Convert to matrix form [A|b] fprintf('SYSTEM 1:\n') fprintf('Original equations:\n') fprintf('8x + 12y = -24\n') fprintf('(7/18)x + (5/9)y = -1\n\n')
% Multiply second equation by 18 to eliminate fractions % 8x + 12y = -24 % 7x + 10y = -18
A1 = [8 12; 7 10]; b1 = [-24; -18]; augmented1 = [A1 b1];
fprintf('Augmented matrix [A|b]:\n') disp(augmented1)
% Calculate RREF rref1 = rref(augmented1); fprintf('Reduced Row Echelon Form:\n') disp(rref1)
% Extract solution x1 = rref1(1,3); y1 = rref1(2,3);
fprintf('Solution:\n') fprintf('x = %.2f\n', x1) fprintf('y = %.2f\n\n', y1)
% SYSTEM 2 % (x-y)/16 = 1/4 % x-y = 4
% Rearrange to standard form: % x - y = 4 % x - y = 4
fprintf('SYSTEM 2:\n') fprintf('Original equations:\n') fprintf('x - y = 4\n') fprintf('x - y = 4\n\n')
A2 = [1 -1; 1 -1]; b2 = [4; 4]; augmented2 = [A2 b2];
fprintf('Augmented matrix [A|b]:\n') disp(augmented2)
% Calculate RREF rref2 = rref(augmented2); fprintf('Reduced Row Echelon Form:\n') disp(rref2)
fprintf('Analysis of System 2:\n') fprintf('The RREF shows that this system has infinitely many solutions.\n') fprintf('The solution can be written as:\n') fprintf('x = t\n') fprintf('y = t - 4\n') fprintf('where t is any real number.\n\n')
% Verify solutions % System 1 fprintf('Verification of System 1 solution:\n') eq1_check = 8x1 + 12y1 + 24; eq2_check = 7x1 + 10y1 + 18; fprintf('Equation 1 check (should be ≈ 0): %.10f\n', eq1_check) fprintf('Equation 2 check (should be ≈ 0): %.10f\n\n', eq2_check)
% Create plots to visualize solutions % System 1 x = -5:0.1:5; y_eq1 = (-8x - 24)/12; y_eq2 = (-7x - 18)/10;
figure(1) plot(x, y_eq1, 'b-', 'LineWidth', 2, 'DisplayName', '8x + 12y = -24') hold on plot(x, y_eq2, 'r-', 'LineWidth', 2, 'DisplayName', '7x + 10y = -18') plot(x1, y1, 'ko', 'MarkerSize', 10, 'MarkerFaceColor', 'k', 'DisplayName', 'Solution') grid on xlabel('x') ylabel('y') title('System 1: Unique Solution') legend('Location', 'best') text(x1+0.2, y1, sprintf('(%.2f, %.2f)', x1, y1))
% System 2 figure(2) y_eq = x - 4; plot(x, y_eq, 'g-', 'LineWidth', 2, 'DisplayName', 'x - y = 4') grid on xlabel('x') ylabel('y') title('System 2: Infinite Solutions (x - y = 4)') legend('Location', 'best')
% Plot some example points t_values = [-2, 0, 2, 4]; x_points = t_values; y_points = t_values - 4; hold on plot(x_points, y_points, 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r', 'DisplayName', 'Example Points') for i = 1:length(t_values) text(x_points(i)+0.2, y_points(i), sprintf('(%.0f, %.0f)', x_points(i), y_points(i))) end
% SYSTEM 1 % -24 - 8x = 12y % 1 + (5/9)y = -(7/18)x
% Rearrange to standard form (ax + by = c): % 8x + 12y = -24 % (7/18)x + (5/9)y = -1
% Convert to matrix form [A|b] fprintf('SYSTEM 1:\n') fprintf('Original equations:\n') fprintf('8x + 12y = -24\n') fprintf('(7/18)x + (5/9)y = -1\n\n')
% Multiply second equation by 18 to eliminate fractions % 8x + 12y = -24 % 7x + 10y = -18
A1 = [8 12; 7 10]; b1 = [-24; -18]; augmented1 = [A1 b1];
fprintf('Augmented matrix [A|b]:\n') disp(augmented1)
% Calculate RREF rref1 = rref(augmented1); fprintf('Reduced Row Echelon Form:\n') disp(rref1)
% Extract solution x1 = rref1(1,3); y1 = rref1(2,3);
fprintf('Solution:\n') fprintf('x = %.2f\n', x1) fprintf('y = %.2f\n\n', y1)
% SYSTEM 2 % (x-y)/16 = 1/4 % x-y = 4
% Rearrange to standard form: % x - y = 4 % x - y = 4
fprintf('SYSTEM 2:\n') fprintf('Original equations:\n') fprintf('x - y = 4\n') fprintf('x - y = 4\n\n')
A2 = [1 -1; 1 -1]; b2 = [4; 4]; augmented2 = [A2 b2];
fprintf('Augmented matrix [A|b]:\n') disp(augmented2)
% Calculate RREF rref2 = rref(augmented2); fprintf('Reduced Row Echelon Form:\n') disp(rref2)
fprintf('Analysis of System 2:\n') fprintf('The RREF shows that this system has infinitely many solutions.\n') fprintf('The solution can be written as:\n') fprintf('x = t\n') fprintf('y = t - 4\n') fprintf('where t is any real number.\n\n')
% Verify solutions % System 1 fprintf('Verification of System 1 solution:\n') eq1_check = 8x1 + 12y1 + 24; eq2_check = 7x1 + 10y1 + 18; fprintf('Equation 1 check (should be ≈ 0): %.10f\n', eq1_check) fprintf('Equation 2 check (should be ≈ 0): %.10f\n\n', eq2_check)
% Create plots to visualize solutions % System 1 x = -5:0.1:5; y_eq1 = (-8x - 24)/12; y_eq2 = (-7x - 18)/10;
figure(1) plot(x, y_eq1, 'b-', 'LineWidth', 2, 'DisplayName', '8x + 12y = -24') hold on plot(x, y_eq2, 'r-', 'LineWidth', 2, 'DisplayName', '7x + 10y = -18') plot(x1, y1, 'ko', 'MarkerSize', 10, 'MarkerFaceColor', 'k', 'DisplayName', 'Solution') grid on xlabel('x') ylabel('y') title('System 1: Unique Solution') legend('Location', 'best') text(x1+0.2, y1, sprintf('(%.2f, %.2f)', x1, y1))
% System 2 figure(2) y_eq = x - 4; plot(x, y_eq, 'g-', 'LineWidth', 2, 'DisplayName', 'x - y = 4') grid on xlabel('x') ylabel('y') title('System 2: Infinite Solutions (x - y = 4)') legend('Location', 'best')
% Plot some example points t_values = [-2, 0, 2, 4]; x_points = t_values; y_points = t_values - 4; hold on plot(x_points, y_points, 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r', 'DisplayName', 'Example Points') for i = 1:length(t_values) text(x_points(i)+0.2, y_points(i), sprintf('(%.0f, %.0f)', x_points(i), y_points(i))) end
% System 1: First pair of equations % -24 - 8x = 12y % 1 + (5/9)y = -(7/18)x
% Rearranging to solve for y: % From first equation: y = (-24 - 8x)/12 % From second equation: y = -(7/18)x - 9/5
x1 = -10:0.1:10; % Create x range y1_eq1 = (-24 - 8x1)/12; % First equation y1_eq2 = -(7/18)x1 - 9/5; % Second equation
figure(1) plot(x1, y1_eq1, 'r-', x1, y1_eq2, 'b-') title('System 1: Intersection of Linear Equations') xlabel('x-axis') ylabel('y-axis') legend('−24−8x=12y', '1+(5/9)y=−(7/18)x') grid on
% System 2: Second pair of equations % (x-y)/16 = 1/4 % x-y = 4
x2 = -10:0.1:10; y2_eq1 = x2 - 4; % From second equation, simpler form y2_eq2 = x2 - 4; % From first equation, simplified
figure(2) plot(x2, y2_eq1, 'r-', x2, y2_eq2, 'b-') title('System 2: Parallel Lines') xlabel('x-axis') ylabel('y-axis') legend('(x-y)/16 = 1/4', 'x-y = 4') grid on
% System 3: Third set of equations % 8x + 12y = 62 % -11x - 4y = 8 % -7x = 14
% First solve for x from the last equation % x = -2
% Substitute x = -2 into first equation: % 8(-2) + 12y = 62 % -16 + 12y = 62 % 12y = 78 % y = 6.5
x3 = -2; % The x-value is fixed at -2 y3 = 6.5;
figure(3) plot(x3, y3, 'ro', 'MarkerSize', 10) title('System 3: Solution Point') xlabel('x-axis') ylabel('y-axis') grid on axis([-5 5 0 10])
% System 4: Fourth set of equations % w - 3y = 0 % 2w - 2x = 0 % 2w - x = 0 % -6w + 4x = 0
% This system uses w instead of y and has homogeneous equations % Let's plot the relationship between x and w
x4 = -10:0.1:10; w4_eq1 = x4/2; % From second equation: w = x/2 w4_eq2 = x4/2; % From third equation: w = x/2
figure(4) plot(x4, w4_eq1, 'r-', x4, w4_eq2, 'b-') title('System 4: Relationship between x and w') xlabel('x-axis') ylabel('w-axis') legend('2w - 2x = 0', '2w - x = 0') grid on