Matlab基礎總結和習題提示

      網友投稿 866 2025-04-04

      安裝與使用說明:https://blog.csdn.net/zhangrelay/article/details/79622079

      網頁版本:https://blog.csdn.net/zhangrelay/article/details/79529824

      濃縮指令備忘錄和習題提示:

      下載鏈接::https://share.weiyun.com/5XlV19a 密碼:ebu4qp

      推薦使用新版matlab,如2017a、2017b等。

      中文官網:http://cn.mathworks.com/

      中文論壇:http://www.ilovematlab.cn/forum.php

      幫助文檔:http://cn.mathworks.com/help/

      對應實驗1到實驗8:

      Matlab習題提示:

      實驗1:

      %1.1

      clc;

      %1.2

      x0=10;v0=15;a=-9.84;t=5;

      x=x0+v0*t+0.5*a*t.^2;

      disp(x)

      %1.3 ln log() log log10() 180 = pi x.*x x*x

      z1=2*sin(pi*85/180)/(1+exp(2))

      x=[2 1+2i;-0.45 5]

      z2=0.5*log(x+sqrt(1+x^2))

      t=0:0.5:2.5

      z3=(t>=0&t<1).*(t.^2)+(t>=1&t<2).*(t.^2-1)+(t>=2&t<3).*(t.^2-2*t+1)

      %1.4 plot()

      x=0:0.1:10;

      y=2*exp(-0.2*x);

      plot(x,y);

      %1.5 exa1 exa2 exa8....

      實驗2:

      %zeros(n)... linspace(1,5,5)... logspace(1,5,5.5)...A[] A()...A.*B

      %A*B...rank()...eig(A)...det(A)

      %2.1

      %2.2

      %2.3 x=A\B A*x=B

      %2.4

      randn(6,6)

      %2.5 help rand ...

      rand('state',0)

      a=rand(2,2)

      s1=num2str(a)

      ss=sprintf('%.10e\n',a)

      fprint('%.5g\',a)

      s_sscan=sscanf(ss,'%f',[3,2])

      %2.6

      %2.7 P=UI=I2R linspace

      Rs=linspace(50,50,1001);Vs=linspace(120,120,1001);

      Rl=0:0.1:100;

      Il=Vs./(Rs+Rl);

      Pl=(Il.*Il).*Rl;

      [Plmax,Rlnum]=max(Pl)

      plot(Rl,Pl)

      實驗3:

      %plot(),subplot(),figure(),hold on,bar(),

      %area(),pie(),hist(),stem(),stairs,plot3(),

      %mesh(),surf(),view(),

      %3.1 %3.2 %3.3%3.4%3.5%3.6%Q

      x=-10:0.1:10;

      y=sqrt((64-x.*x)/2.0);

      y1=-sqrt((64-x.*x)/2.0);

      plot(x,y);

      hold on;

      plot(x,y1);

      t=-10:0.1:10;

      x=sin(t);

      y=cos(t);

      plot(x,y);

      y=sin(x.^-1);

      plot(x,y);

      fplot(x,y); %error

      function Y = myfun(x)

      Y(:,1) = x(:);

      Y(:,2) = sin(x(:).^-1);

      fh = @myfun;

      fplot(fh,[-2 2])

      x=-3:0.1:3;

      y=-3:0.1:3;

      [X,Y]=meshgrid(x,y);

      Z=-X.^2+Y.^2;

      figure(1);

      mesh(X,Y,Z);

      figure(2);

      surf(X,Y,Z);

      a=1;

      x=a*sin(t);

      y=sqrt(25-a^2)*cos(t);

      subplot(2,2,1)

      plot(x,y);

      a=2;

      x=a*sin(t);

      y=sqrt(25-a^2)*cos(t);

      subplot(2,2,2)

      plot(x,y);

      a=3;

      x=a*sin(t);

      y=sqrt(25-a^2)*cos(t);

      subplot(2,2,3)

      plot(x,y);

      a=4;

      x=a*sin(t);

      y=sqrt(25-a^2)*cos(t);

      subplot(2,2,4)

      plot(x,y);

      實驗4:

      4.1 注意syms x y 與 x=sym('6'); 具體過程如下:

      syms x y;

      x=sym('6');

      y=sym('5');

      sprintf('z符號表達式求解結果為:')

      z=(x+1)/(sqrt(3+x)-sqrt(y))

      4.2 factor() 參考例題即可

      4.3 simple() 具體示例如下:

      syms p1 p2 x

      F=sin(p1)*cos(p2)-cos(p1)*sin(p2)

      sprintf('F化簡結果為')

      f=simple(F)

      G=(4*x^2+8*x+3)/(2*x+1)

      sprintf('G化簡結果為')

      g=simple(G)

      syms x;

      f=x^6+1;

      s=factor(f)

      syms x;

      f=x^2-1;

      s=factor(f)

      syms h n x;

      L=limit((log(x+h)-log(x))/h,h,0)

      M=limit((1-x)/n^n,n,inf)

      N=limit((1-x/n)^n,n,inf)

      syms a x;

      y=sin(a*x);

      A=diff(y,x)

      B=diff(y,a)

      C=diff(y,x,2)

      syms n;

      S=symsum(1/n^2,1,inf)

      S1=symsum(1/n^2,1,10)

      S2=symsum(n,1,100)

      syms x;

      f=x*sin(x);

      F=fourier(f)

      syms x y;

      x=sym('6');

      y=sym('5');

      z=(x+1)/(sqrt(3+x)-sqrt(y))

      syms x1 x2;

      f=sin(x1)*cos(x2)-cos(x1)*sin(x2);

      p=simple(f)

      syms x y;

      f=x^4-y^4;

      s=factor(f)

      syms x1 x2;

      syms p1 p2 x

      F=sin(p1)*cos(p2)-cos(p1)*sin(p2)

      sprintf('F化簡結果為')

      f=simple(F)

      G=(4*x^2+8*x+3)/(2*x+1)

      sprintf('G化簡結果為')

      g=simple(G)

      syms x y;

      x=sym('6');

      y=sym('5');

      sprintf('z符號表達式求解結果為:')

      z=(x+1)/(sqrt(3+x)-sqrt(y))

      實驗5:選擇結構(if else)示例有錯誤。

      5.1 if else習題

      word=input('請輸入一個字符,','s')

      if word>='A'&word<='Z'

      sprintf('是大寫字母啊!!!')

      char(word+1)

      elseif word>='a'&word<='z'

      sprintf('是小寫字母啊!!!')

      char(word-1)

      elseif word>='1'&word<='9'

      sprintf('是數字啊!!!')

      char(word)

      else

      sprintf('都是些什么啊!!!')

      char(word)

      end

      5.2 switch case習題

      word=input('請輸入字符串,','s')

      switch word

      case 'Monday'

      disp('1')

      case 'Sunday'

      disp('7')

      case 'Happy'

      disp('666')

      otherwise

      disp('Unknown')

      end

      5.3 參考如下:

      A=[2 2 2;3 4 3];B=[1 2;3 2;6 6];

      try

      sprintf('1')

      C=A*B

      catch

      sprintf('2')

      C=A.*B

      end

      5.4

      a=20;b=-2;c=0;d=1;

      disp('a>b'),a>b

      disp('b>d'),b>d

      disp('a>b&c>d'),a>b&c>d

      disp('a==b'),a==b

      disp('a&b>c'),a&b>c

      disp('~~b'),~~b

      5.5 類似5.4

      思考題

      s=0;

      a=2;

      b=1;

      t=0;

      for i=1:16

      s=s+a./b;

      t=a;

      a=a+b;

      b=t;

      end

      s

      實驗六

      具體參考指導書

      實驗七

      效果圖:

      代碼(請慎重使用全局變量):

      function varargout = ex7gui(varargin)

      % EX7GUI M-file for ex7gui.fig

      % EX7GUI, by itself, creates a new EX7GUI or raises the existing

      % singleton*.

      %

      % H = EX7GUI returns the handle to a new EX7GUI or the handle to

      % the existing singleton*.

      %

      % EX7GUI('CALLBACK',hObject,eventData,handles,...) calls the local

      % function named CALLBACK in EX7GUI.M with the given input arguments.

      %

      % EX7GUI('Property','Value',...) creates a new EX7GUI or raises the

      % existing singleton*. Starting from the left, property value pairs are

      % applied to the GUI before ex7gui_OpeningFunction gets called. An

      % unrecognized property name or invalid value makes property application

      % stop. All inputs are passed to ex7gui_OpeningFcn via varargin.

      %

      % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one

      % instance to run (singleton)".

      %

      % See also: GUIDE, GUIDATA, GUIHANDLES

      % Copyright 2002-2003 The MathWorks, Inc.

      % Edit the above text to modify the response to help ex7gui

      % Last Modified by GUIDE v2.5 28-Mar-2018 14:02:01

      % Begin initialization code - DO NOT EDIT

      gui_Singleton = 1;

      gui_State = struct('gui_Name', mfilename, ...

      'gui_Singleton', gui_Singleton, ...

      'gui_OpeningFcn', @ex7gui_OpeningFcn, ...

      'gui_OutputFcn', @ex7gui_OutputFcn, ...

      'gui_LayoutFcn', [] , ...

      'gui_Callback', []);

      if nargin && ischar(varargin{1})

      gui_State.gui_Callback = str2func(varargin{1});

      end

      if nargout

      [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

      else

      gui_mainfcn(gui_State, varargin{:});

      end

      % End initialization code - DO NOT EDIT

      % --- Executes just before ex7gui is made visible.

      function ex7gui_OpeningFcn(hObject, eventdata, handles, varargin)

      % This function has no output args, see OutputFcn.

      % hObject handle to figure

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles structure with handles and user data (see GUIDATA)

      % varargin command line arguments to ex7gui (see VARARGIN)

      % Choose default command line output for ex7gui

      handles.output = hObject;

      global BB;

      % Update handles structure

      guidata(hObject, handles);

      % UIWAIT makes ex7gui wait for user response (see UIRESUME)

      % uiwait(handles.figure1);

      % --- Outputs from this function are returned to the command line.

      function varargout = ex7gui_OutputFcn(hObject, eventdata, handles)

      % varargout cell array for returning output args (see VARARGOUT);

      % hObject handle to figure

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles structure with handles and user data (see GUIDATA)

      % Get default command line output from handles structure

      varargout{1} = handles.output;

      % --- Executes on button press in pushbutton1.

      function pushbutton1_Callback(hObject, eventdata, handles)

      % hObject handle to pushbutton1 (see GCBO)

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles structure with handles and user data (see GUIDATA)

      %figure(1);

      AA = str2double(get(handles.edit1,'String'));

      global BB

      x=-10:0.1:10;

      %plot(x,sin(x)+cos(x)+x)

      line(x,AA*(sin(BB*x)+cos(BB*x))+x)

      % --- Executes on button press in pushbutton2.

      function pushbutton2_Callback(hObject, eventdata, handles)

      Matlab基礎題總結和習題提示

      % hObject handle to pushbutton2 (see GCBO)

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles structure with handles and user data (see GUIDATA)

      cla;

      % --- Executes on button press in pushbutton3.

      function pushbutton3_Callback(hObject, eventdata, handles)

      % hObject handle to pushbutton3 (see GCBO)

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles structure with handles and user data (see GUIDATA)

      function edit1_Callback(hObject, eventdata, handles)

      % hObject handle to edit1 (see GCBO)

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles structure with handles and user data (see GUIDATA)

      % Hints: get(hObject,'String') returns contents of edit1 as text

      % str2double(get(hObject,'String')) returns contents of edit1 as a double

      %AA = str2double(get(hObject,'String'))

      % --- Executes during object creation, after setting all properties.

      function edit1_CreateFcn(hObject, eventdata, handles)

      % hObject handle to edit1 (see GCBO)

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.

      % See ISPC and COMPUTER.

      if ispc

      set(hObject,'BackgroundColor','white');

      else

      set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));

      end

      % --- Executes on button press in radiobutton1.

      function radiobutton1_Callback(hObject, eventdata, handles)

      % hObject handle to radiobutton1 (see GCBO)

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles structure with handles and user data (see GUIDATA)

      % Hint: get(hObject,'Value') returns toggle state of radiobutton1

      if get(hObject,'Value')

      grid on;

      else

      grid off;

      end

      % --- Executes on slider movement.

      function slider2_Callback(hObject, eventdata, handles)

      % hObject handle to slider2 (see GCBO)

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles structure with handles and user data (see GUIDATA)

      % Hints: get(hObject,'Value') returns position of slider

      % get(hObject,'Min') and get(hObject,'Max') to determine range of slider

      global BB

      BB=50*get(hObject,'Value')+1

      % --- Executes during object creation, after setting all properties.

      function slider2_CreateFcn(hObject, eventdata, handles)

      % hObject handle to slider2 (see GCBO)

      % eventdata reserved - to be defined in a future version of MATLAB

      % handles empty - handles not created until after all CreateFcns called

      % Hint: slider controls usually have a light gray background, change

      % 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.

      usewhitebg = 1;

      if usewhitebg

      set(hObject,'BackgroundColor',[.9 .9 .9]);

      else

      set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));

      end

      --

      實驗八:

      simulink

      注意模塊一定要確保準確,參數正確。

      ----~~~~----

      MATLAB

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:WPS表格中常用函數使用教程
      下一篇:Word中應該怎樣自動編號公式?(word中公式如何自動編號)
      相關文章
      色偷偷亚洲第一综合| 亚洲久本草在线中文字幕| 国产亚洲一区二区手机在线观看| 亚洲精品无码永久在线观看男男| 亚洲中文无码线在线观看| 亚洲国产精品一区| 亚洲VA成无码人在线观看天堂| 国产亚洲精品福利在线无卡一| 亚洲人成影院在线观看| 亚洲av高清在线观看一区二区| 亚洲国产精品18久久久久久| 亚洲人成人伊人成综合网无码| 国产亚洲国产bv网站在线 | 亚洲国产韩国一区二区| 亚洲经典在线中文字幕| 亚洲av成人一区二区三区| 亚洲欧洲自拍拍偷午夜色| 18亚洲男同志videos网站| 亚洲黑人嫩小videos| 久久亚洲熟女cc98cm| 亚洲精品中文字幕无乱码| 亚洲精品国产手机| 亚洲伊人久久大香线焦| 亚洲午夜电影在线观看高清 | 亚洲中文字幕无码日韩| 国产亚洲精品国看不卡| 亚洲香蕉网久久综合影视| 国产V亚洲V天堂A无码| 亚洲国产精品久久久久| 亚洲视频在线不卡| 亚洲最大黄色网站| 99热亚洲色精品国产88| 亚洲乱妇熟女爽到高潮的片| 亚洲爆乳少妇无码激情| 国产亚洲精品美女| 亚洲五月午夜免费在线视频| 亚洲精品狼友在线播放| 久久精品九九亚洲精品| 亚洲13又紧又嫩又水多| 亚洲精品无码永久在线观看男男| 亚洲成av人片天堂网老年人 |