Looking for a suitable command in Matlab

  • Context: MATLAB 
  • Thread starter Thread starter hokhani
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

This discussion focuses on solving an overdetermined system of equations in MATLAB to find constant coefficients c and d in the equation "cf(x) + dg(x) = h(x)". The user employs the least squares method to achieve this, utilizing a row vector for x, converting it to a column vector, and constructing a matrix A from the functions f(x) and g(x). The MATLAB command "params = A\b;" is used to compute the least squares solution, resulting in a 2x1 vector containing the values of c and d.

PREREQUISITES
  • Understanding of MATLAB syntax and operations
  • Familiarity with vector and matrix manipulation in MATLAB
  • Knowledge of least squares method for solving equations
  • Basic understanding of numerical functions and their implementation in MATLAB
NEXT STEPS
  • Explore MATLAB's built-in functions for numerical optimization
  • Learn about MATLAB's matrix operations and their applications
  • Investigate advanced techniques for solving overdetermined systems
  • Study the implementation of other numerical methods in MATLAB, such as gradient descent
USEFUL FOR

Mathematics students, engineers, and data analysts who are using MATLAB for numerical analysis and optimization tasks.

hokhani
Messages
601
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
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
6K