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

조회 수: 6 (최근 30일)
Patrick
Patrick 2019년 1월 15일
댓글: Torsten 2019년 1월 21일
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;

채택된 답변

Jan
Jan 2019년 1월 16일
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
Walter Roberson
Walter Roberson 2019년 1월 20일
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, []);
Torsten
Torsten 2019년 1월 21일
@Patrick: What you program is not the Gauss-Newton method.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2019년 1월 15일
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
Patrick
Patrick 2019년 1월 15일
Thanks for the answer but I have already used the fminsearch and i'm not aloud to use that one either
Torsten
Torsten 2019년 1월 16일
You are allowed to use "fsolve" ? Or do you have to write your own nonlinear equation solver ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by