Looking for a suitable command in Matlab

  • Context: MATLAB 
  • Thread starter Thread starter hokhani
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 1K views
hokhani
Messages
610
Reaction score
22
I have a vector for instance
Code:
x=1:200;
and three functions of this vector as f(x) and g(x) and h(x) numerically. I want to find the values of the constant coefficients c and d in "cf(x)+dg(x)=h(x)". Is there any way in Matlab to calculate these coefficients directly?
 
Physics news on Phys.org
You have an overdetermined system of equations: 200 equations and 2 unknowns. One way to solve this is do use least squares. In MATLAB I would do least squares like:

x = 1:200; %row vector
x = x(:); %make a column vector
A = [f(x), g(x)]; % 200 x 2 matrix
b = h(x); %100 x 1 vector
params = A\b; %lease squares solution of A*params = b; params is a 2x1 vector
c = params(1);
d = params(2);

jason