Editing a function and then using fzero
Mostrar comentarios más antiguos
I am trying to write a code that uses fzero on a function.
As I see it the only one way to edit and ran scripts on a function is by declaring it as syms type.
But syms does not work with fzero.
How should I approach it?
* I am trying to solve a nonlinear equation with two variables. So I have made two syms variables and wrote two function with those syms variables. So I get two syms functions. Then I use subs on two of the functions in order to have a one variable equation using those two functions (sub syms type to a scalar). I a adding the code.
clear
clc
%variables
u0 = 4*pi*10e-7;
Ms = 0.8;
gamma = 1;
Ku=1;
D = 0;
A = 1;
sinfei = sin(-pi/2);
delta=1;
syms d W
for m = 1:2
surfaceV(m) = (sin((pi/gamma)*W*m)/sinh((pi^2/gamma)*delta*m))^2*((1-exp(-(2*pi/gamma)*m*d))/m);
volumeV(m) = (sin((pi/gamma)*W*m)/cosh((pi^2/gamma)*delta*m))^2*((exp(-(2*pi/gamma)*m*d)+((2*pi/gamma)*m*d)-1)/m);
end
surfaceEnergy = (1/2)*u0*Ms^2*(1-2*W/gamma)^2+((2*pi*u0*Ms^2*delta^2)/(gamma*d))*sum(surfaceV);
volumeEnergy = ((2*pi*u0*Ms^2*delta^2*sinfei^2)/(gamma*d))*sum(surfaceV);
dW_surfaceEnergy = diff(surfaceEnergy,W);
dW_volumeEnergy = diff(volumeEnergy,W);
non_volumeORsurface_energy=-((2*delta*Ku+2*A/delta+pi*D*sinfei)/W^2); %Non volume nor surface energies for total energy solution
d_vector = double(linspace(100,200,3));
W_d=double(zeros(1,length(d_vector),'uint64'));
for m = 1:length(d_vector)
W_d(m)=double(fzero(subs(symfun(dW_surfaceEnergy+dW_volumeEnergy+non_volumeORsurface_energy,W),d,d_vector(m)),50));
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Calculus en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!