首页 > 代码库 > MATLAB实验

MATLAB实验

数据处理

实验目的

进一步熟悉MATLAB数据处理基本功能。

实验内容

成绩评估

 

姓名

课1

课2

课3

课4

课5

总分

平均

标准差

优良率

学生1

97

86

89

94

96

462

92.4

4.7223

1

学生2

70

94

87

79

60

390

78

13.472

0.4

学生3

66

60

73

92

71

362

72.4

12.054

0.2

学生4

94

65

66

78

61

394

72.8

13.442

0.2

学生5

69

92

66

78

87

392

78.4

11.194

0.4

学生6

85

77

67

78

86

393

78.6

7.6354

0.4

学生7

98

95

76

76

99

444

88.8

11.777

0.6

总分

579

569

524

575

560

 

 

 

 

平均

82.714

81.286

74.857

82.143

80

 

 

 

 

标准差

579

569

524

575

560

 

 

 

 

优良率

0.57

0.57

0.28

0.28

0.57

 

 

 

 

 
score=fix(rand(7,5)*40+60);sunmlie=sum(score);sumhang=sum(score‘);meanlie=mean(score);meanhang=mean(score‘);a=meanhang‘;stdlie=std(score);stdhang=std(score‘);youliang=score>=80;youlianghang=sum(youliang‘)/5;youlianglie=sum(youliang)/7;

曲线作图

做出如下曲线,sin(x),sin(3x),sin(x)+sin(3x),x2,x3,1/x,log2(x),log10(x).

含多曲线合成图,多子图合成图,用title命令,label命令,axis命令对图形进行规范化。

 C++代码

 1 // Simulation.h: interface for the CSimulation class. 2 // 3 ////////////////////////////////////////////////////////////////////// 4  5 #if !defined(SIMULATION_H) 6 #define SIMULATION_H 7  8 #include <vector> 9 #include "Rocket.h"10 #include "Spark.h"11 using namespace std;12 13 class CSimulation  14 {15 public:16 //Member functions:17     //Constructor18     CSimulation();19     //Deconstructor20     virtual ~CSimulation();21     //Display all the particles22     void Display();23     //Calculate total number of particles24     int GetParticleNum();25     //One Euler step of the simulation26     void EulerStep();27     //When a rocket reaches its top height, it explodes and calls this function to generate sparks28     void Explode(float posx, float posy, float RocketSpeed, float* color);29     //When a key is pressed, Simulation calls this function to generate a rocket30     void FireRocket(float pos, float* color);31     //Set the speed of the wind32     void SetWindSpeed(float windSpeedValue);33     //Set Total Explosions34     void SetTotalExplosions(int explosions);35     36 //Member variables:37     //Vector of CRocket. Rockets in this vector are either still flying or generating sparks38     vector<CRocket*> rockets;39     //Vector of CSpark.40     vector<CSpark*> sparks;41     //Delta time for a Euler step.42     float deltaT;43     //Velocity of the wind in x direction44     float windSpeed;45     unsigned int totalExplosions;46 };47 48 #endif // !defined(SIMULATION_H)

 

 

 

代码:

t=0:100;y1=sin(t);y2=sin(3*t);y3=sin(t)+sin(3*t);y4=t.^2;y5=t.^3;y6=t.^-1;y7=log2(t);y8=log10(t);subplot(1,1,1),plot(t,y1,‘r‘);hold on;plot(t,y2,‘g‘);hold on;plot(t,y3,‘b‘);legend(‘sin(t)‘,‘sin(3t)‘,‘sin(t)+sin(3t)‘);title(‘y1/y2/y3‘);xlabel(‘t‘);ylabel(‘y‘);axis([0 20 -2 2]);grid on;figure(4);subplot(1,1,1),plot(t,y4,‘r‘);hold on;plot(t,y5,‘g‘);legend(‘t^2‘,‘t^3‘);title(‘y4/y5‘);xlabel(‘t‘);ylabel(‘y‘);figure(3);subplot(1,1,1),plot(t,y6,‘b‘);legend(‘1/t‘);title(‘y6‘);xlabel(‘t‘);ylabel(‘y‘);figure(2);subplot(1,1,1),plot(t,y7,‘r‘);hold on;plot(t,y8,‘g‘);legend(‘log2(t)‘,‘log10(t)‘);title(‘y7/y8‘);xlabel(‘t‘);ylabel(‘y‘);figure(1);

  

MATLAB实验