|
"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
|