What is wrong with this MATLAB code?

前端 未结 4 584
情深已故
情深已故 2020-12-21 07:19

I am trying to do following in MATLAB,

global a b c d e f g h l;
A=[1 3;3 2];
B=[a 0;0 b];
C=[d 0;e f];
Ctranspose=transpose(C);
D=[sqrt(d) 0;0 sqrt(f)];
E=C         


        
4条回答
  •  無奈伤痛
    2020-12-21 08:14

    You have to change the order of your program.

    d = 4567; % some value necessary
    e = 1234; % some value necessary
    f = 4567; % some value necessary
    for a=1:10
     for b=1:10
    
        A=[1 3;3 2];
        B=[a 0;0 b];
        C=[d 0;e f];
        Ctranspose=transpose(C);
        D=[sqrt(d) 0;0 sqrt(f)];
        E=Ctranspose/D;
        Etranspose=transpose(E);
        K=A+E;
        M=E*D*Etranspose;
    
    
       if  K==M
         print(a);
         print(b);
         print(d);
         print(e);
         print(f);
    
       end
     end
    end
    

    You not seem to have correctly understood the basic concept of a programming language. In a programming language (unlike mathematical notation) the statements are commands that are executed sequencially, one after another. All values that are needed in a computation have to be available when that command is executed, hence the updated execution order is necessary for intended operation.

提交回复
热议问题