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. ubunbu退出nano

    无意中进入ubuntu GNU nano ctrl+x即可退出

  2. 深入理解利用new创建对象的执行过程以Person p=new Person("张三",20);为例

    代码如下: class Person { private String name="haha"; private int age; private static String co ...

  3. nginx日志配置,以及日志轮询

    一.为nginx配置错误日志 Nginx错误日志是调试nginx的重要手段,属于核心功能模块的参数(ngx_core_module)该参数名字为err_log,是放在Main区块中全局配置 err_l ...

  4. if-else 与 switch-case语句

    if语句就是起一个判断作用,在c语言中有三种表达形式:1.if(表达式)语句:pl.   if(x==y)printf("%d",x);         //*  "== ...

  5. runtime 实现方法交换 viewwillappear方法

    1.新建分类 #import "UIViewController+swizzling.h"#import <objc/runtime.h> @implementatio ...

  6. Spring Cloud之Zuul网关集群

    Nginx+Zuul 一主一备 或者 轮训多个 在微服务中,所有服务请求都会统一到Zuul网关上. Nginx 配置: #user nobody; worker_processes 1; #error ...

  7. LightOJ 1138 二分

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...

  8. 使用button的:after伪类选择器内容的跳动

    按钮的css样式,想要作个美观一点的按钮,使用:after伪类选择器在按钮后跟随"!!"的符号,但点击按钮时按钮的值内容动,但跟随的"!!"符合不动,这样看起来 ...

  9. Runtime Error(ACCESS_VIOLATION)

    1.     while(scanf("%d",&n) )// 错误,会出现  Runtime Error(ACCESS_VIOLATION) while(scanf(&q ...

  10. html设置编码

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />