Fminsearch curve fitting does not fit properly
Mostra commenti meno recenti
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.

Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
