matlab中logistic
时间: 2023-08-23 07:14:16 浏览: 127
Matlab绘制Logistic图,matlab画logistic曲线,matlab
5星 · 资源好评率100%
在Matlab中,可以使用封装好的logistic函数来绘制logistic函数的图像。具体的代码如下所示:
```
x = -10:0.01:10;
y = 1./(1+exp(-x));
plot(x,y,'r','linewidth',1.5);
xlabel('x')
```
这段代码会生成一个x轴范围为-10到10的logistic函数的图像。\[1\]
另外,在Matlab中,可以使用以下代码来求解logistic回归的目标函数:
```
train_x1=\[ones(size(train_x,1),1),train_x\];
test_x1=\[ones(size(test_x,1),1),test_x\];
w=zeros(size(train_x1,2),1);
lr=0.001;%学习率
pred_f= train_x1*w; %预测出的方程式取值
pred_y=1./(1+exp(-pred_f)); %Sigmoid函数
d_w=(train_y-pred_y)'*train_x1;
w=w+lr*d_w';
```
这段代码中,train_x是训练数据,train_y是训练标签,test_x是测试数据,w是权重参数,lr是学习率。通过迭代更新权重参数,可以得到logistic回归的目标函数。\[2\]
另外,如果想要提高绘图的速度,可以将绘图函数移出循环。以下是一个示例代码:
```
clc,clear,close all;
x0 = 0.5;
u = 0:0.001:4; %自定义步长改变迭代次数
xn = ft_logistic(x0,length(u)-1,u);
plot(u(2:end),xn,'b.',"linewidth",1.2)
grid on
function \[yn\] = ft_logistic(x0,num_len,u)
xn = x0;
for j = 1:num_len
u_i = u(j);
for i = 1:j
xn(i+1) = u_i*xn(i).*(1-xn(i));
end
yn(1,j) = xn(j);
end
end
```
这段代码会生成一个logistic函数的迭代图像。\[3\]
#### 引用[.reference_title]
- *1* [Matlba绘制Logistic函数特殊形式的sigmoid函数图像(含程序)](https://blog.csdn.net/weixin_50892810/article/details/126784003)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Logistic回归——二分类 —— matlab](https://blog.csdn.net/qq_25990967/article/details/123518959)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [MATLAB绘制Logistic混沌映射的分叉图](https://blog.csdn.net/wayne6515/article/details/124775718)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文