• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

[matlab]一道笔试题

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

 

x=[1 1; 1 -1; -1 -1; -1 1]';
X=-2:0.01:2;  Y=X; N=length(X);  [X,Y]=meshgrid(X,Y);
Z1=0;Z2=0;Z3=0;Z4=0;
for i=1:N
    for j=1:N
        Z1(i,j)=norm([X(i,j);Y(i,j)]-x(:,1))^2;        Z2(i,j)=norm([X(i,j);Y(i,j)]-x(:,2))^2;
        Z3(i,j)=norm([X(i,j);Y(i,j)]-x(:,3))^2;        Z4(i,j)=norm([X(i,j);Y(i,j)]-x(:,4))^2;
    end
end
theta=[1 -1 1 -1]; M=[-5 -2 0 2 5]*0.1;
gamma=1/2;
Z=theta(1)*exp(-gamma*Z1)+theta(2)*exp(-gamma*Z2)+theta(3)*exp(-gamma*Z3)+theta(4)*exp(-gamma*Z4);
subplot(2,3,1); hold on;plot(x(1,:),x(2,:),'ro');contour(X,Y,Z,M);title('\gamma=0.5');
gamma=1;
Z=theta(1)*exp(-gamma*Z1)+theta(2)*exp(-gamma*Z2)+theta(3)*exp(-gamma*Z3)+theta(4)*exp(-gamma*Z4);
subplot(2,3,2);  hold on;plot(x(1,:),x(2,:),'ro');contour(X,Y,Z,M);title('\gamma=1');
gamma=10;
Z=theta(1)*exp(-gamma*Z1)+theta(2)*exp(-gamma*Z2)+theta(3)*exp(-gamma*Z3)+theta(4)*exp(-gamma*Z4);
subplot(2,3,3); hold on; plot(x(1,:),x(2,:),'ro');contour(X,Y,Z,M);title('\gamma=10');
gamma=1;
theta(1)=0.1; 
Z=theta(1)*exp(-gamma*Z1)+theta(2)*exp(-gamma*Z2)+theta(3)*exp(-gamma*Z3)+theta(4)*exp(-gamma*Z4);
subplot(2,3,4); hold on; plot(x(1,:),x(2,:),'ro');contour(X,Y,Z,M);title('\theta_1=0.1');
theta(1)=0.5; 
Z=theta(1)*exp(-gamma*Z1)+theta(2)*exp(-gamma*Z2)+theta(3)*exp(-gamma*Z3)+theta(4)*exp(-gamma*Z4);
subplot(2,3,5);  hold on;plot(x(1,:),x(2,:),'ro');contour(X,Y,Z,M);title('\theta_1=0.5');
theta(1)=5; 
Z=theta(1)*exp(-gamma*Z1)+theta(2)*exp(-gamma*Z2)+theta(3)*exp(-gamma*Z3)+theta(4)*exp(-gamma*Z4);
subplot(2,3,6);  hold on;plot(x(1,:),x(2,:),'ro');contour(X,Y,Z,M);title('\theta_1=5');

  

循环结构:for语句
格式:
for 循环变量=表达式1:表达式2:表达式3
循环体
end
【注】:表达式1:循环变量初值,
表达式2:步长,为1时,可省略;
表达式3:循环变量终值。
或:
for循环变量=矩阵表达式
循环体
end
【注】:执行过程是依次将矩阵的各列元素赋给循环变量,然后执行循环体语句,直至各列元素处理完毕。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Matlab,C++存取二进制发布时间:2022-07-22
下一篇:
matlab局部特征检测与提取(问题与特征)发布时间:2022-07-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap