Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Looking for a suitable command in Matlab

  1. May 11, 2015 #1
    I have a vector for instance
    Code (Text):

    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?
  2. jcsd
  3. May 13, 2015 #2


    User Avatar
    Science Advisor
    Gold Member

    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);

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook