Question: Please use matlab to fix this code the matrix dimensions are not matching up, I'm trying to calculate the values of C1, C2, and C3
Please use matlab to fix this code the matrix dimensions are not matching up, I'm trying to calculate the values of C1, C2, and C3 to solve the Matrix. Please post fixed code script and output of fixed script.
My Code:
%-----Matrix Needed to be solved------- % 6*C_1 + 3*C_2 + 2*C_3 = 2 ----- (Eq. 1) % -5*C_1 - 4*C_2 - 3*C_3 = 3 ----- (Eq. 2) % C_1 + C_2 + C_3 = 4 ----- (Eq. 3)
function [] = solve()
% User input for number of points n = input('Enter the number of points to Plot: ');
x = randi([-4 4], 1, n); % X values between -4 and 4
% Defining Denominators D1 = x-1; D2 = x-2; D3 = x-3;
R = @(x) (6 + 5*x + 4*x^2)/((D1).*(D2).*(D3)); % R(x) formula
% y equals the R(x) value per for each x value y = []; for z = 1:n y(z) = x(z); end A = [] for z = 1:n for i = 1:n A(z, i) = 1/x(z) - i; end end
c = inv(A)*transpose(y) % Rx = R1(x) + R2(x) + R3(x) = c1/(x-1) + c2/(x-2) + c3/(x-3)
Rx = @(x) c(1)./D1 + c(2)./D2 + c(3)./D3; y = []; for z = 1:n y(z)=Rx(x(z)); end %-----------Check-------------
% should equal zero Rx_Check = sum(abs(y))- sum(abs(y))
end
Command Window/ Errors:
Enter the number of points to Plot: 5
A =
[]
Warning: Matrix is singular to working precision. > In ExerciseM8 (line 45)
c =
NaN NaN NaN NaN NaN
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in ExerciseM8 (line 52) y(z)=Rx(x(z));
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
