Thread Subject:
Solving an equation with multiple variables

Subject: Solving an equation with multiple variables

From: John

Date: 17 Feb, 2011 10:32:05

Message: 1 of 2

I have to solve a problem where I am given one equation aX+bY+c=D. I am given D, X, and Y in the form of 100 samples of data for each, and using that I am supposed to determine a,b,c.

my code takes the form of
syms a
syms b
syms c
for z=3:3:length(D)
[a,b,c]=solve('D(z)=a*X(z)+b*Y(z)+c', 'D(z-1)=a*X(z-1)+b*Y(z-1)+c', 'D(z-2)=a*X(z-2)+b*Y(z-2)+c'
end

but the answers I get are in terms of the variables with a combination of the z z-1 and z-2 parts of it, not an actual number. I am guessing there is something wrong with my approach any help would be appreciated. I am not giving the exact code because this is for a HW assignment and I am just trying to determine how to write this code, not get you to write it for me.

Thanks for your help

Subject: Solving an equation with multiple variables

From: Miroslav Balda

Date: 17 Feb, 2011 22:35:05

Message: 2 of 2

"John" wrote in message <ijitf5$p05$1@fred.mathworks.com>...
> I have to solve a problem where I am given one equation aX+bY+c=D. I am given D, X, and Y in the form of 100 samples of data for each, and using that I am supposed to determine a,b,c.
>
> my code takes the form of
> syms a
> syms b
> syms c
> for z=3:3:length(D)
> [a,b,c]=solve('D(z)=a*X(z)+b*Y(z)+c', 'D(z-1)=a*X(z-1)+b*Y(z-1)+c', 'D(z-2)=a*X(z-2)+b*Y(z-2)+c'
> end
>
> but the answers I get are in terms of the variables with a combination of the z z-1 and z-2 parts of it, not an actual number.

Hi,
If you are trying to solve your problem symbolically, You may get numbers after eveluating the final formulae. However, if you have column vectors of numerical data, you may proceed in the following way:

A = [X(z) Y(z) ones(length(X(z),1))
       X(z+1) Y(z-1) ones(length(X(z-1),1))
       X(z+2) Y(z-2) ones(length(X(z-2),1))];
B = [D(z);D(z-1);D(z-2)];
p = A\B;
a = p(1);
b = p(2);
c = p(3);

Maybe, I am wrong, however, for numerical data it should work.

Mira

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us