each value calculation for Mag Field

9 次查看(过去 30 天)
Hi all, Kindly check this code. for each value of magnetic field there is value of angle alpha. I want to calculate zeeman energy and then for each angle alpha i want magnetization
clc
clear all
close all
nrows = 1;
si = (2.2 * 9.27e-24)* ones(nrows)
Si = sum(si); % Sum of rows for calculation of MAGNETIZATION
M_Si = sum(Si) % MAGNETIZATION ( Total magnetic moment of the array )
alpha = 30 * pi/180;% Initial angle of the magnetic moment with x-axis( No Field Applied )
beta = 20 * pi/180; % The angle at which Magnetic Field is applied to align all the moments
B_steps = 10;
applied_field = linspace(0,1,B_steps);
alpha_reduce = -linspace(alpha,beta,B_steps);
for i = 1:B_steps
alpha_trial = alpha + alpha_reduce(i)
zeeman(i) = - applied_field(i) * M_Si *cos(alpha_trial)
end
Magnetization = M_Si * cos(alpha_trial)
plot(applied_field,Magnetization,'*')
xlabel('Magnetization')
ylabel('applied_field')

采纳的回答

Walter Roberson
Walter Roberson 2015-5-26
At the end of your "for" loop, alpha_trial is going to be the last value it was in going through the loop, so it is going to be (alpha + alpha_reduce(B_steps)). Are you sure that is what you want?
Your code could be vectorized as
zeeman = -applied_field .* Msi .* cos(alpha + alpha_reduce);
But after your "for" loop, you do not use the value of zeeman(). So you might as well not calculate it at all.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by