为什么 lsqnonlin 工具箱不能用单个方程拟合单个参数?

问题描述

为什么 lsqnonlin(Matlab 工具箱)不能处理这个单一的方程和一个参数。

我应该如何进行这种配合?预测 theta = -1 的正确值?这是我的 Matlab 代码

clear all,clc,close all

h = 0.01;
x = -2:h:2
%data production:
theta = -1
step_funtion =@(x,theta) ((x+theta)>0)*1;

y1 =  step_funtion(x,theta);

%ploting the data
hold on
figure(1)
plot(x,y1,'mo')

%data for regression
x1 = x;
f1 = y1;

theta0 = [0]; %initial guess
[theta] = lsqnonlin(@(x) f(x,x1,f1),theta0) % nonlin least sq. (theta = prediction )

%plot solution of the prediciton: 
plot(x1,step_funtion(x1,theta),'b-')
legend('original theta = -1','predicted theta')

function r = f(theta,f1)
r1 = ((x1+theta)>0)*1-f1;
r = [r1];
end

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)