Solve a system with values taken from tables
3 views (last 30 days)
Show older comments
Dear all,
I have a system with 2 springs I can solve with these two equations:
Fv = k1*x1 + k2*x2
Fh*l = k1*x1*t/2 - k2*x2*t/2
Now if k1 and k2 are constant, I can easily solve the system in many ways. Also if k1 and k2 are not constant, but functions of x1 and x2, I can add other 2 equations and solve the problem. But in my case I struggle to approximate k1 and k2 with 2 functions, so I would like to take their values from 2 tables/matrices where in the first column I have the displacement x and the in other the stiffness k for each of the 2 springs.
Can you help me to solve this problem? Thanks.
0 Comments
Answers (1)
Rahul Goel
on 17 Jul 2015
Hi Mattia,
I understand that you are trying to solve a system of equations by taking values from a given table.
I could interpret two possible cases from your question mentioning “k1” and “k2” being the functions of “x1” and “x2”: 1. “k1” is a function of “x1” AND “k2” is a function of “x2”:
In this case, you can try fitting in your data using “ polyfit ” function to compute the parameters of the polynomial function. “Polyfit” enables you to fit your data in a polynomial of degree “n” that is the best fit for your data. It also has the functionalities to fit a polynomial to a given set of points, which in your case is a table.
2. “k1” is a function of “x1” and “x2” AND “k2” is also a function of “x1” and “x2”:
In this case, there are two independent variables, so you can try using “ fmincon ” function (which is a part of Optimization Toolbox). For this, you will have to formulate your problem as an optimization problem. You can define an objective function and the error (E.g. – least square, weighted least square and so on), and “fmincon” would find the parameters of the function defining k1, k2 while using x1 and x2 as independent variables. Once you have the form of the functions defining k1 and k2, you can use them to solve your system of equations.
You can also try using “ polyfitn ” function to do the same which fits a polynomial regression model of one or more independent variables, of the general form. Following documentation describes the elaborate usage of “polyfitn” function: http://www.mathworks.com/matlabcentral/fileexchange/34765-polyfitn
Hope this solves your issue.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!