How to find 3 unknows with Least square a*cosh(b*x)+c, not using toolbox?

6 views (last 30 days)
I have a least square problem with the equation a*cosh(b*x)+c, where the problem lies in that I do not know how to solve the unfamiliar each separately. I have solved the problem with fminsearch and fittype (toolbox) but I want to solve it without the toolbox.
If it would be a+cos(b*x) I would know how to solve it. Here i got stuck because if i proceed with this(and make it work...) i would only end up with the constans a and c, like you would with a regular 2nd degree polynomial. So to the question: How do i determine a,b and c with the help of the dataset x and y, That is using method of least squares to interpolate/approximate f(x) in regards to the data and not using toolbox like the above and lsqcurvefit?
with regards P
The x and y values are in a separate file.
data = load('koordinater');
x = data.x;
y = data.y;
g = fittype('a*cosh(b*x) + c','coeff',{'a','b','c'});
options = fitoptions(g);
fitobject = fit(x',y',g,options);
MKAM = (fitobject.a)*cosh((fitobject.b)*x) + fitobject.c;

Accepted Answer

Jan
Jan on 16 Jan 2019
You have a system of equations:
a * cosh(b * x) + c - y = 0
with x and y are the given. Now you search the least-squares-solution, which finds [a,b,c] such that the equations are solved as good as possible.
You can use a set of different root finding algorithms, see https://en.wikipedia.org/wiki/Root-finding_algorithm:
  • Bisection method
  • False position (regula falsi)
  • Interpolation
  • Newton's method (and similar derivative-based methods)
  • Secant method
  • Steffensen's method
  • Inverse interpolation
I assume that you have learned something about one or more of these methods and the purpose of this homework is to implement it. We cannot guess, which one is preferred, but you can and should ask your teacher.
  4 Comments
Walter Roberson
Walter Roberson on 20 Jan 2019
Your code does not make much mathematical sense unless bx, x, and sbx are column vectors. However if they are column vectors then you cannot just append 1 and have it work: you would need to append a vector of 1's.
J = [bx(:) a*x(:).*sbx(:) ones(numel(x),1)];
h = J\f(:);
p = p - reshape(h, 1, []);

Sign in to comment.

More Answers (1)

Torsten
Torsten on 15 Jan 2019
data = load('koordinater');
x = data.x;
y = data.y;
fun = @(p)sum((p(1)*cosh(p(2)*x)+p(3)-y).^2);
p0 = [1;1;1];
p = fminsearch(fun,p0)
  4 Comments
Patrick
Patrick on 15 Jan 2019
Thanks for the answer but I have already used the fminsearch and i'm not aloud to use that one either
Torsten
Torsten on 16 Jan 2019
You are allowed to use "fsolve" ? Or do you have to write your own nonlinear equation solver ?

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!