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
【注】:执行过程是依次将矩阵的各列元素赋给循环变量,然后执行循环体语句,直至各列元素处理完毕。

[matlab]一道笔试题的更多相关文章

  1. Java中有关构造函数的一道笔试题解析

    Java中有关构造函数的一道笔试题解析 1.详细题目例如以下 下列说法正确的有() A. class中的constructor不可省略 B. constructor必须与class同名,但方法不能与c ...

  2. 一道笔试题来理顺Java中的值传递和引用传递

      题目如下: private static void change(StringBuffer str11, StringBuffer str12) { str12 = str11; str11 = ...

  3. 一道笔试题和UML思想 ~

    一句软件工程界的名言,让我想起了一个和一道笔试题有关的故事.希望更多的人了解 UML 背后的思想比他的语法更重要,是笔者写作本文的一点小愿望. 一.从一句软件工程名言说起 对很多事情的处理上,东西方都 ...

  4. 由阿里巴巴一道笔试题看Java静态代码块、静态函数、动态代码块、构造函数等的执行顺序

    一.阿里巴巴笔试题: public class Test { public static int k = 0; public static Test t1 = new Test("t1&qu ...

  5. 转:一道笔试题-将int型数组强制转换为char*,再求strlen,涉及大小端

    写出如下程序运行结果: #include<stdio.h> #include<string.h> int main() { int a[2000]; char *p = (ch ...

  6. golang 中 string 转换 []byte 的一道笔试题

    背景 去面试的时候遇到一道和 string 相关的题目,记录一下用到的知识点.题目如下: s:="123" ps:=&s b:=[]byte(s) pb:=&b s ...

  7. 通过一道笔试题浅谈javascript中的promise对象

    因为前几天做了一个promise对象捕获错误的面试题目,所以这几天又重温了一下promise对象.现在借这道题来分享下一些很基础的知识点. 下面是一个面试题目,三个promise对象捕获错误的例子,返 ...

  8. IGT一道笔试题

    1到n连续的n个数 输入m 得出m个有序序列 比如 输入为n=5 ,m=3 则输出 543 542 541 532 531 521  432 431 421 321 当前长度为i,每个位上的取之范围为 ...

  9. 一道笔试题:给定编码规则,实现decode()方法

    public class CodeDecode {     /*变换函数encode()顺序考察已知字符串的字符,按以下规则逐组生成新字符串:       (1)若已知字符串的当前字符不是大于0的数字 ...

随机推荐

  1. JS一些碎知识点

    一些js基本知识点 Doctype 浏览器渲染模式 渲染模式发展历史 在多年以前(IE6诞生以前),各浏览器都处于各自比较封闭的发展中(基本没有兼容性可谈).随着WEB的发展,兼容性问题的解决越来越显 ...

  2. 第六篇 javascript面向对象

    一.闭包 闭包是指可以包含自由(未绑定到特定对象)变量的代码块. 「闭包」,是指拥有多个变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分. 闭包是个函数,而它「记 ...

  3. org.eclipse.core.resources.bak文件导致MyEclipse每次关闭时无法保存文件

    MyEclipse关闭时提示如下信息 Problems occurred while trying to save the state of the workbench. Internal Error ...

  4. BZOJ 1656 [Usaco2006 Jan] The Grove 树木:bfs【射线法】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1656 题意: 给你一个n*m的地图,'.'表示空地,'X'表示树林,'*'表示起点. 所有 ...

  5. fatal error C1071: unexpected end of file found in comment

    1.错误 #include<iostream> using namespace std; int main() { ..... return 0; } //如果把注释放到这里了,那么提交就 ...

  6. JSP分页1

    分页 1.什么分页? 第N页/共M页 首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页 口 go 分页的优点:只查询一页,不用查询所有页! 2.分页数据 页面的数据都是由Servl ...

  7. (转)Java 调用 C++ (Java 调用 dll)

    转自: http://www.cnblogs.com/baokang/p/4979243.html 因为要做点图形处理的项目,需要在Java中调用dll库,所以开发的第一步是研究了一下Java Jni ...

  8. hdu-5642 King's Order(数位dp)

    题目链接: King's Order Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Othe ...

  9. stl_map.h

    stl_map.h // Filename: stl_map.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http://blo ...

  10. ACM学习历程—CodeForces 601A The Two Routes(最短路)

    题目链接:http://codeforces.com/problemset/problem/601/A 题目大意是有铁路和陆路两种路,而且两种方式走的交通工具不能在中途相遇. 此外,有铁路的地方肯定没 ...