Matlab基础总结和习题提示

网友投稿 746 2022-05-30

安装与使用说明: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)

% 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)

Matlab基础题总结和习题提示

% 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小时内删除侵权内容。

上一篇:怎么在Excel表格中将数字0显示为横线
下一篇:【云驻共创】1/10代码,1/6时间,如何基于Mindx快速开发一个商业AI应用
相关文章