当前位置: 首页 > 工具软件 > One Step > 使用案例 >

[MATLAB调试笔记]Update magnetic field in one step

钮边浩
2023-12-01
function [field] = bfield(field,prm)
    % Update magnetic field in one step
    X2 = prm.X2;
    f = field; % reference to Field obj

    f.by(X2) = f.by(X2) + f.ez(  X2) - f.ez(X2-1);
    f.bz(X2) = f.bz(X2) - f.ey(X2+1) + f.ey(X2  );

    f.by(prm.nxp2)= f.by(2);%对称边界条件
    f.bz(prm.nxp2)= f.bz(2);
    f.by(1)   = f.by(prm.nxp1);
    f.bz(1)   = f.bz(prm.nxp1);
end

>> prm.X2

ans =

  Columns 1 through 16

     2     3     4     5     6     7     8     9    10    11    12    13    14    15    16    17

  Columns 17 through 32

    18    19    20    21    22    23    24    25    26    27    28    29    30    31    32    33

  Columns 33 through 48

    34    35    36    37    38    39    40    41    42    43    44    45    46    47    48    49

  Columns 49 through 64

    50    51    52    53    54    55    56    57    58    59    60    61    62    63    64    65

  Columns 65 through 80

    66    67    68    69    70    71    72    73    74    75    76    77    78    79    80    81

  Columns 81 through 96

    82    83    84    85    86    87    88    89    90    91    92    93    94    95    96    97

  Columns 97 through 112

    98    99   100   101   102   103   104   105   106   107   108   109   110   111   112   113

  Columns 113 through 128

   114   115   116   117   118   119   120   121   122   123   124   125   126   127   128   129

>> f.by(X2)

ans =

     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0

>>  f.ez(  X2)

ans =

     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0

>> f.by(X2) = f.by(X2) + f.ez(  X2) - f.ez(X2-1)

f = 

  Field with properties:

     ex: [130×1 double]
     ey: [130×1 double]
     ez: [130×1 double]
     by: [130×1 double]
     bz: [130×1 double]
    rho: [130×1 double]
    ajx: [130×1 double]
    ajy: [130×1 double]
    ajz: [130×1 double]

>> f.by(X2) = f.by(X2) + f.ez(  X2) - f.ez(X2-1)

f = 

  Field with properties:

     ex: [130×1 double]
     ey: [130×1 double]
     ez: [130×1 double]
     by: [130×1 double]
     bz: [130×1 double]
    rho: [130×1 double]
    ajx: [130×1 double]
    ajy: [130×1 double]
    ajz: [130×1 double]

>> f.bz(X2) = f.bz(X2) - f.ey(X2+1) + f.ey(X2  )

f = 

  Field with properties:

     ex: [130×1 double]
     ey: [130×1 double]
     ez: [130×1 double]
     by: [130×1 double]
     bz: [130×1 double]
    rho: [130×1 double]
    ajx: [130×1 double]
    ajy: [130×1 double]
    ajz: [130×1 double]

>> bfield(field,prm)
Unrecognized function or variable 'bfield'.
 
Did you mean:
>> field(field,prm)
Unable to use a value of type Field as an index.
 
>> bfield(field,prm)

ans = 

  Field with properties:

     ex: [130×1 double]
     ey: [130×1 double]
     ez: [130×1 double]
     by: [130×1 double]
     bz: [130×1 double]
    rho: [130×1 double]
    ajx: [130×1 double]
    ajy: [130×1 double]
    ajz: [130×1 double]

>> 

 类似资料: