Solving for the coefficent of linear equations with one known coefficent
Posted
by
CppLearner
on Stack Overflow
See other posts from Stack Overflow
or by CppLearner
Published on 2012-10-10T20:01:36Z
Indexed on
2012/10/10
21:37 UTC
Read the original article
Hit count: 326
matlab
clc;
clear all;
syms y a2 a3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [ 0.5 0.25 0.125 ] [ a2 ] [ y ]
% [ 1 1 1 ] [ a3 ] = [ 3 ]
% [ 2 4 8 ] [ 6 ] [ 2 ]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M = [0.5 0.25 0.125; 1 1 1; 2 4 8];
t = [a2 a3 6];
r = [y 3 2];
sol = M * t'
s1 = solve(sol(1), a2) % solve for a2
s2 = solve(sol(2), a3) % solve for a3
This is what I have so far. These are my output
sol =
conj(a2)/2 + conj(a3)/4 + 3/4
conj(a2) + conj(a3) + 6
2*conj(a2) + 4*conj(a3) + 48
s1 =
- conj(a3)/2 - 3/2 - Im(a3)*i
s2 =
- conj(a2) - 6 - 2*Im(a2)*i
sol looks like what we would have if we put them back into equation form:
0.5 * a2 + 0.25 * a3 + 0.125 * a4
a2 + a3 + a4 = 3
2*a2 + 4*a3 + 8*a4 = 2
where a4 is known == 6.
My problem is, I am stuck with how to use solve to actually solve these equations to get the values of a2 and a3.
s2 solve for a3 but it doesn't match what we have on paper (not quite).
a2 + a3 + 6 = 3 should yield a3 = -3 - a2.
because of the imaginary. Somehow I need to equate the vector solution sol to the values [y 3 2] for each row.
© Stack Overflow or respective owner