Denis Gorbunov wrote:
Yep, I didn't include any result because it takes too long for the program to arrive at it. Now I've included the plot I'm after - Mtotal(B). As you can see, it makes no sense.
Thats no surprise given the way the functions are defined.
In my opinion, dE() should return the energy minimized with respect to alpha and phi.
In what form? a vector? a 61x2 matrix ? What did you had in mind?
I want to minimize the initial expression, that is, E(B,alpha,phi).
Its a function in 3 variables, so you would need the derivatives wrt all 3. Also, how yould you cope with multiple (local) minima? And if you want the calculation being done for a constant B, I guess both partial derivates should be zero at the same time. I would suggest using either a solve block with Find() (using the two partial derivative) or one with Minimize().
I also don't understand why your function Mtotal should still be dependent on alpha and Phi and why you had setup ranges for those angles. f() and g() should already return the "optimal" values for those angles, as I think. Also f() and g() would not be dependent on alpha and Phi.