1. 程式人生 > >MATLAB實驗

MATLAB實驗

ner spa direction using order hold on tin ati 標準

數據處理

實驗目的

進一步熟悉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     //Constructor
18     CSimulation();
19     //Deconstructor
20     virtual ~CSimulation();
21     //Display all the particles
22     void Display();
23     //Calculate total number of particles
24     int GetParticleNum();
25     //One Euler step of the simulation
26     void EulerStep();
27     //When a rocket reaches its top height, it explodes and calls this function to generate sparks
28     void Explode(float posx, float posy, float RocketSpeed, float* color);
29     //When a key is pressed, Simulation calls this function to generate a rocket
30     void FireRocket(float pos, float* color);
31     //Set the speed of the wind
32     void SetWindSpeed(float windSpeedValue);
33     //Set Total Explosions
34     void SetTotalExplosions(int explosions);
35     
36 //Member variables:
37     //Vector of CRocket. Rockets in this vector are either still flying or generating sparks
38     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 direction
44     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實驗