MATLAB Looking for a suitable command in Matlab

  • Thread starter Thread starter hokhani
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
To determine the coefficients c and d in the equation "cf(x) + dg(x) = h(x)" using MATLAB, an overdetermined system of equations can be solved using least squares. The approach involves creating a column vector from the range 1 to 200 and forming a matrix A with the functions f(x) and g(x). The target vector b is derived from h(x). By applying the least squares solution with the command A\b, the coefficients can be extracted from the resulting parameters vector. This method effectively provides the required coefficients for the equation.
hokhani
Messages
561
Reaction score
18
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
 

Similar threads

Replies
7
Views
2K
Replies
1
Views
4K
Replies
3
Views
2K
Replies
4
Views
2K
Replies
1
Views
2K
Replies
5
Views
6K
Back
Top