Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
3 equations 2 unknows

Subject: 3 equations 2 unknows

From: ravi

Date: 30 May, 2010 00:04:05

Message: 1 of 3

HI,

I have the following 2 equations:

5a + 4b + 7c = 23
3a + 3b + 6c = 20

How can I retrieve unknown constants : a , b and c ?

Thanks
Ravi

Subject: 3 equations 2 unknows

From: Matt Fig

Date: 30 May, 2010 01:26:05

Message: 2 of 3

A = [5 4 7;3 3 6];
b = [23;20];

x = A\b

Subject: 3 equations 2 unknows

From: Greg Heath

Date: 30 May, 2010 10:59:35

Message: 3 of 3

On May 29, 8:04 pm, "ravi " <ravi_...@hotmail.com> wrote:
> HI,
>
> I have the following 2 equations:
>
> 5a + 4b + 7c = 23
> 3a + 3b + 6c = 20
>
> How can I retrieve unknown constants :  a , b and c ?

clear all, close all, clc

A = [ 5 4 7; 3 3 6 ]
b = [ 23; 20 ]

% A*x = b

rankA = rank(A) % 2
sizex = [ size(A,2) size(b,2)] %[ 3 1 ]
rankdef = sizex(1) - rankA % rank deficiency = 1
if rankdef > 0
    disp('Nonunique Solution')
    disp('Can arbitrarily set rankdef components of x to 0,')
    disp('or can add any multiple of the unit null solution, ')
    disp('x0, where A*x0 = 0, norm(x0) = 1')
end
x0 = null(A) % [ 0.30151 -0.90453 0.30151 ]'
normx0 = norm(x0) % sqrt(sum(x0.^2)) = 1
e0 = A*x0 % [ 0 2.2204e-016 ]'

% The "BASIC" solution.
% Number of zero solution components >= rankdef

xb = A\b % [ -0.22222 0 3.4444 ]'
msexb = mse(A*xb-b) % 0
normxb = norm(xb) % 3.4516

% The "MINIMUM NORM" solution.
% No solution of the form x = xb + const*x0 will have
% a smaller norm than xmn

xmn = pinv(A)*b % [ -0.51515 0.87879 3.1515 ]'
msexmn = mse(A*xmn-b) % 6.3109e-30
normxmn = norm(xmn) % 3.3121

Hope this helps.

Greg

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us