⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_10.m

📁 用matlab实现的拥有图形化的交互界面
💻 M
📖 第 1 页 / 共 3 页
字号:
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function M_YG_Callback(hObject, eventdata, handles)
% hObject    handle to M_ZPS1_YG (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function M_XY_Callback(hObject, eventdata, handles)
% hObject    handle to M_ZPS1_XY (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function M_ZY_Callback(hObject, eventdata, handles)
% hObject    handle to M_ZPS1_ZY (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function M_ZPS_Callback(hObject, eventdata, handles)
% hObject    handle to M_ZPS1_ZPS (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function M_ZGH_Callback(hObject, eventdata, handles)
% hObject    handle to M_ZPS1_ZGH (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --- Executes on button press in M_OK.
function M_OK_Callback(hObject, eventdata, handles)
% hObject    handle to M_OK (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global topicnum;
global P;
if topicnum==1;
    y=6*pi*(1/tan(12.5))+4;
    answer=['y=',num2str(y)];
    set(handles.M_answer,'String',answer);
end

if topicnum==2
    p=[13 182 -184 2503];
    r=roots(p);
    answer=num2str(r);
    set(handles.M_answer,'String',answer);
end

if topicnum==3
    y=exp(3)+(3.47)*log(14)+287^(1/4);
    answer=['方程的解是:',num2str(y)];
    set(handles.M_answer,'String',answer);
end

if topicnum==4
     yfy=sin(-pi/2):0.05:cos(0);
     answer=['元素个数:',num2str(length(yfy)),'  第十个元素是:',num2str(yfy(10))];
     set(handles.M_answer,'String',answer);
end

if topicnum==5
    axes(handles.M_axes);
    x=0:pi;
    y=1;
    z=(4/pi)*sin(y)+sin(3*y)/3+sin(5*y)/5;
    plot(y,z);
    hold on;
    x=-pi:0;
    y=-1;
    z=(4/pi)*sin(y)+sin(3*y)/3+sin(5*y)/5;
    %plot(x,y,'b');
    plot(x);
    title('第五题');
end

if topicnum==6
    r=10;
    z=0:0.1:4;
    x=r*(z-sin(z));
    y=r*(1-cos(z));
    axes(handles.M_axes);
    plot(x,y);
    title('第六题');
    set(handles.M_answer,'String','答案如图');
end

if topicnum==7
    A=[7 14 -6;12 -5 9;-5 7 15];
    B=[95;-50;145];
    C=inv(A)*B;
    answer=num2str(C);
    set(handles.M_answer,'String',answer);
end

if topicnum==8
    x=[-15 -8 9 8 5];
    y=[-20 12 -4 8 9];
    answer=num2str(find(x>y));
    set(handles.M_answer,'String',answer);
end

if topicnum==9
    A=0;
    for k=1:10
        A=A+5*k*k*k;
    end
    answer=num2str(A);
    set(handles.M_answer,'String',answer);
end

if topicnum==10
    k=1;
    y=0;
    while y<=2000
        y=y+3^k-2^k;
        k=k+1;
    end
    answer=num2str(k-1);
    set(handles.M_answer,'String',answer);
end

if topicnum==11
    AA=xlsread('A.xls');
    set(handles.M_answer,'String',num2str(AA));
    axes(handles.M_axes);
    plot(AA);
    title('第十一题');
end

if topicnum==14
    a=[12,5,-2,3];
    b=[3,-7,4];
    [m,n]=deconv(a,b);
    answer=['商是:',num2str(m),'          余数是:',num2str(n)];
    set(handles.M_answer,'String',answer);
end

if topicnum==15
    a=[10 -9 -6 12];
    b=[5,-4,-12,8];
    c=conv(a,b);
    answer=num2str(c);
    set(handles.M_answer,'String',answer);
end

if topicnum==16
    r=[1,3+5i,3-5i];
    p=poly(r);
    set(handles.M_answer,'String',num2str(p));
    axes(handles.M_axes);
    plot(p);
    title('第十六题');
end

if topicnum==17
    x=str2num(get(handles.M_edit1,'String'));
    y1=12*x^3+5*x^2-2*x+3;
    y2=3*x^2-7*x+4;
    p1=[12 5 -2 3];
    p2=[3 -7 4];
    k1=polyval(p1,x);
    k2=polyval(p2,x);
    K=k1/k2;
    set(handles.M_answer,'String',num2str(K));
end

if topicnum==18
    x=str2num(get(handles.M_edit1,'String'));
    answer=num2str(m_compute(x));
    set(handles.M_answer,'String',answer);
end

if topicnum==19
    A=[3 5 -4;-8 -1 33;-17 6 -9];
    for ii=1:3
        for jj=1:3
            if (A(ii,jj)>1||A(ii,jj)==1)
                B(ii,jj)=A(ii,jj)*A(ii,jj)+20;
            end
        end
    end
    answer=num2str(B);
    set(handles.M_answer,'String',answer);
    xlswrite('B.xls',B);
end

if topicnum==20
    A=[3 5 -4;-8 -1 33;-17 6 -9];
    B=find(A>=0);
    A(B)=A(B).*A(B);
     B=find(A>=0);
    A(B)=A(B)+20;
    answer=num2str(A);
    set(handles.M_answer,'String',answer);
end

if topicnum==21
    year=str2num(get(handles.M_edit2,'String'));
    x=10000;
    y=0;
    a=1;  
    while (y<=1000000)
        y=(1+year)*a*(x+a*x);
        a=a+1;
    end
    answer=['需要',num2str(a),'年才能够一百万元'];
    set(handles.M_answer,'String',answer);
end

if topicnum==22
    x=str2num(get(handles.M_edit3,'String'));
    if x==0||x==360||x==-360
        d=1;
    elseif x==90||x==-270
        d=2;
    elseif x==180||x==-180
        d=3;
    elseif x==270||x==-90
        d=4;
    elseif (x>0&&x<90)||(x>-360&&x<-270)
        d=5;
    elseif (x>90&&x<180)||(x>-270&&x<-180)
        d=6;
    elseif (x>180&&x<270)||(x>-180&&x<-90)
        d=7;
    elseif (x>270&&x<360)||(x>-90&&x<0)
        d=8;
    elseif (x>360)||(x<-360)
        d=0;
    end
    switch d
        case 0
            set(handles.M_answer,'String','输入有误,请重新输入');
        case 1
            set(handles.M_answer,'String','东');
        case 2
            set(handles.M_answer,'String','北');
        case 3
            set(handles.M_answer,'String','西');
        case 4
            set(handles.M_answer,'String','南');
        case 5
            set(handles.M_answer,'String','东北');
        case 6
            set(handles.M_answer,'String','西北');
        case 7
            set(handles.M_answer,'String','西南');
        case 8
            set(handles.M_answer,'String','东南');
    end  
end

if topicnum==24
    x=[-10:0.1:10]
    y=sin(2*x).*cos(x);
    axes(handles.M_axes);
    subplot(2,2,1)
    plot(x,y)
    z=sin(x)+cos(2*x);
    subplot(2,2,3)
    plot(x,z)
    m=2*cos(x)-sin(x).*sin(x);
    subplot(2,2,4)
    plot(x,m)
end

if topicnum==25
    x = -pi:pi/20:pi;
    y1=2*cos(x)-sin(x).*sin(x);
    y2=sin(2*x).*cos(x);
    axes(handles.M_axes);
    plot(x,y1,'-.b',x,y2,'r')
    h = legend('y1','y2',2);
    gtext('y1');
    gtext('y2');
end

if topicnum==26
    x=-10:0.1:10;
    y=sin(x);
    set(handles.M_answer,'String','答案如图');
    axes(handles.M_axes);
    plot(x,y,'b-.d','markersize',10,'MarkerEdgeColor','r','MarkerFaceColor','g');
    title('第二十六题');
end

if topicnum==27
    axes(handles.M_axes);
    B=rgb2gray(P);
    subimage(B);
    set(handles.M_answer,'String','答案如图');
end

if topicnum==28
    syms x;
    a=diff(cos(x)^2*sin(x)+2*exp(1)^(-3*x)+1/sqrt(x),x);
    b=diff(cos(x)^2*sin(x)+2*exp(1)^(-3*x)+1/sqrt(x),x,3);
    answer=[a,b]
    set(handles.M_answer,'String','答案在命令窗口显示');
end

if topicnum==29
    syms x y;%定义符号变量 
    y1=x.*x;
    y2=x*y.^y;
    a=int(y1,x,2,5);%求定积分
    b=int(y2,y,0,5);
    %answer=['对x积分:',num2str(a),'对y积分:',mat2str(b)];
    answer=[a,b]
    set(handles.M_answer,'String','答案在命令窗口显示');
end

if topicnum==30
    syms x a t h;
    y1=limit(sin(a*x)./x,x,0)
    y2=limit((x-3)/(x.^2+9),x,3)
    y3=limit((sin(x+h)-sin(x))/h,h,0)
    y4=limit((sin(x+h)-sin(x))/h,x,0)
    answer=[y1,y2,y3,y4]
    set(handles.M_answer,'String','答案在命令窗口显示');
    %answer=['第一个的极限是:',y1,'第二个的极限是:'num2str(y2),'第三个的极限是:',y3,'第四个的极限是:',y4];
    %set(handles.M_answer,'String',answer);
end



% --- Executes on button press in M_cancel.
function M_cancel_Callback(hObject, eventdata, handles)
% hObject    handle to M_cancel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.M_edit1,'String','');
set(handles.M_edit2,'String','');
set(handles.M_edit3,'String','');



% --------------------------------------------------------------------
function M_ZPS21_Callback(hObject, eventdata, handles)
% hObject    handle to M_ZPS21 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global topicnum;
topicnum=21;
topicstr='21、请用一个循环来计算:用户最初在一个银行帐户中存储10000元,并且在每年的年终都会再存储10000元,假设银行的年利率为x%,无利息税,那么,帐户上要积累1百万元需要多少年?请采用由用户自行输入年利率的方式来进行,其结果应显示在编辑框里。';
set(handles.M_topic,'String',topicstr);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -