{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

solve_system

# solve_system - B = vec2,1:end-1%obtains the first two...

This preview shows page 1. Sign up to view the full content.

function [x y] = solve_system(vec,vec2) %Write a function called solve_system that solves a system of linear %equations. %Your function will have two inputs : %- A vector consisting of the coefficients of the first linear equation % of the form Ax+By=C, which would be [A B C]. %- Another vector consisting of the coefficients of a second line % equation, with the same form as the first input. %Your function should have two outputs: the x and y value of the %solution. A = vec(:,1:end-1); %obtains the first 2 columns of the vector array
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: B = vec2(:,1:end-1); %obtains the first two columns of the vector2 array new = [A;B]; %vertically concatenates the new arrays C = vec(:,end); %gets the last column of the vector array D = vec2(:,end); %gets the last column of the vector2 array new2 = [C;D]; %vertically concatenates the new arrays sol = new\new2; %solves the system of equations by back-dividing x = sol(1,1); %the x value is the 1st entry of the solution y = sol(2,1); %the y value is the 2nd entry of the solution end e...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online