Fminsearch curve fitting does not fit properly

조회 수: 3 (최근 30일)
Jonas Gentner
Jonas Gentner 2021년 11월 19일
댓글: Jonas Gentner 2021년 11월 20일
Hi,
i am trying to fit a simple nonlinear pendulum model to measured data by adjusting the damping constant (parameter estimation).
my pendulum function:
function simY = PendelOde2(b,varargin)
u =1;
m = 0.5035; % [kg] mass
l = 0.1315; % [m] length of pendulum
g = 9.81; % [m/s²] gravitational acceleration
expTime = 0:1e-2:20.02;
tic
ODE_Sol = ode45(@(tt,x) myNonlinearPendulum(tt,x,u,m,g,l,b),[0 200.2],[deg2rad(13.5253),deg2rad(0)]);
simY = deval(ODE_Sol, expTime);
simY = simY(1,:);
toc
function [dx,y] = myNonlinearPendulum(t,x,u,m,g,l,b,varargin)
% Output equation.
y = x(1); % Angular position.
% State equations.
dx = [x(2); ... % Angular position
-(g/l)*sin(x(1))-b/(m*l^2)*x(2) ... % Angular velocity
];
end
end
how i am trying to fit (using fminsearch):
clear;
clc;
load('Pendel1_11_eigen.mat')
x = Pendel1_11_eigen.X.Data;
y = Pendel1_11_eigen.Y.Data;
m = 0.5035; % [kg] mass
l = 0.1315; % [m] length of pendulum
g = 9.81; % [m/s²] gravitational acceleration
b0 = 3.1e-4; % [Nm s] damping constant (to estimate)
[bmin, Smin] = fminsearch(@(b) norm(PendelOde2(b) - y), b0)
y1 = rad2deg(PendelOde2(bmin))
plot(x,y)
hold on
plot(x,y1)
grid
This code is running, but the solution of the optimization does not fit to the data (see plot below). At this point i am a little confused why fminsearch thinks it has found a optimal solution and what i should change to make this work.
Any help is highly appreciated. Thanks in advance.

채택된 답변

Matt J
Matt J 2021년 11월 19일
편집: Matt J 2021년 11월 19일
Plotting your function in an interval around bmin shows that it is a minimum of the function you've provided. So, fminsearch did its job correctly.
The only thing to assume is either that this is a local minimum (you need a better initial guess), or else it is, indeed, the best fit possible given the model you're using.
[bmin, Smin, ef] = fminsearch(@(b) norm(PendelOde2(b) - y), b0);
fun=@(b) norm(PendelOde2(b) - y);
fun=@(b)arrayfun(fun,b);
t=linspace(-1,1,21);
Ft=fun(bmin+t*b0);
plot(t,Ft)
  댓글 수: 1
Jonas Gentner
Jonas Gentner 2021년 11월 20일
Thanks for the reply. The initial guess i am making here with b0 is already a really good fit that i found manually. It is way better than what fminsearch is returning as an optimum. It is hard to find a better initial guess and it shows that the model is capable of fitting to this data.
What i found out in my despair, is that fminsearch is fitting perfectly when i change the length of pendulum parameter from 0.1315 to 0.135. I guess i need to check the pendulum length of my test setup again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parameter Estimation에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by