Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: fsolve
Replies: 1   Last Post: Dec 22, 2011 6:00 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
george veropoulos

Posts: 45
Registered: 6/26/10
fsolve
Posted: Dec 22, 2011 4:42 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi Friend

i created a matlab code to find the roots of a function that dependent
of single varliable x.
When i m trying to runnig the main program the matlab compiler produce the message


??? Error using ==> vertcat
CAT arguments dimensions are not consistent.

Error in ==> energy_new at 115
A=[A11 A12 A13 A14 A15 A16 A17 A18;.../

Error in ==> fsolve at 195
fuser = feval(funfcn{3},x,varargin{:});

Error in ==> det_zero at 21
x(c)=fsolve(@energy_new,steps(c));


my code are as follow

function f=energy_new(x)
%m=size(L);
% format long e
% length in nm

%D=10.;
%L=5.;
%L1=5.;
%in m
%divide by L0=10nm
global V0;
global L;
L0=10.0;
D=60./L0;
L1=L;
%L=5./L0;
%L1=5./L0;


V0=0.858 % in ev
%V0 is 60% of energy gap
%GaAs in region 1 3 5
%InAs in region 2 and 4

%m_0=0.51;%free electron mass in Mev
%%%% EFFECTIVE MASS
m1_star=0.067;
m2_star=0.0278;
m3_star=m1_star;
m4_star=m2_star;
m5_star=m1_star;

%h_bar=1.0;% in fermi unit's
%k vector divided by L0

const=2.498.*10.^3 ;
k_1=(const.*m1_star.*((x./V0)-1)).^(0.5);
k_5=k_1;
k_3=k_1;
k_2=(const.*m2_star.*(x./V0)).^(0.5);
k_4=k_2;
%%%%% MATRIX ELEMENT'S
A11=-exp(i.*k_2.*(D+L));
A12=0;
A13=0;
A14=0;
A15=exp(-i.*k_1.*(D+L))
A16=-exp(i.*k_2.*(D+L));
A17=0;
A18=0;
%
A21=(i.*k_2./m2_star).*exp(i.*k_2.*(D+L));
A22=0;
A23=0;
A24=0;
A25=(i.*k_1./m1_star).*exp(-i.*k_1.*(D+L));
A26=(-i.*k_2./m2_star).*exp(-i.*k_2.*(D+L));
A27=0;
A28=0;

A31=exp(i.*D.*k_2);
A32=-exp(-i.*k_3.*D);
A33=0;
A34=0;
A35=0;
A36=exp(-i.*k_2.*D);
A37=-exp(-i.*k_3.*D);
A38=0;

A41=(i.*k_2./m2_star).*exp(i.*k_2.*D);
A42=-(i.*k_3./m3_star)*exp(i.*k_3.*D);
A43=0;
A44=0;
A45=0;
A46=-(i.*k_2./m2_star).*exp(-i.*k_2.*D);
A47=(i.*k_3./m3_star).*exp(-i.*k_3.*D);
A48=0;

A51=0;
A52=exp(-i.*k_3.*D);
A53=-exp(-i.*k_4.*D);
A54=0;
A55=0;
A56=0;
A57=exp(i.*k_3.*D);
A58=-exp(i.*k_4.*D);

A61=0;
A62=(i.*k_3./m3_star).*exp(-i.*k_3.*D);
A63=-(i.*k_4./m4_star).*exp(-i.*k_4.*D);
A64=0;
A65=0;
A66=0;
A67=-(i.*k_3./m3_star).*exp(i.*k_3.*D);
A68=(i.*k_4./m4_star).*exp(i.*k_4.*D);

A71=0;
A72=0;
A73=exp(-i.*k_4.*(D+L1));
A74=-exp(-i.*k_5.*(D+L));
A75=0;
A76=0;
A77=0;
A78=exp(i.*k_4.*(D+L1));

A81=0;
A82=0;
A83=(i.*k_4./m4_star).*exp(-i.*k_4.*(D+L1));
A84=-(i.*k_5./m5_star).*exp(-i.*k_5.*(D+L1));
A85=0;
A86=0;
A87=0;
A88=-(i.*k_4./m4_star).*exp(k_4.*(D+L1));

A=[A11 A12 A13 A14 A15 A16 A17 A18;.../
A21 A22 A23 A24 A25 A26 A27 A28;.../
A31 A32 A33 A34 A35 A36 A37 A38;.../
A41 A42 A43 A44 A45 A46 A47 A48;..../
A51 A52 A53 A54 A55 A56 A57 A58;.../
A61 A62 A63 A64 A65 A66 A67 A68;.../
A71 A72 A73 A74 A75 A76 A77 A78;.../
A81 A82 A83 A84 A85 A86 A87 A88 ];

%solve(det(A), 'E')
%%%%% magnitude of det
im=imag(det(A));
re=real(det(A));
f=sqrt(det(A).*conj(det(A)));

thiis the function

and the main code



global V0;
global L;

V0=0.858;
%global L;
REsim=zeros(1,10000);
E=zeros(1,10000);
y=zeros(1,10000);
L=zeros(1,10000);
z=zeros(1,10000);
x=zeros(1,10000);

%L ia normalized
L=linspace(0.01,1,100);
steps=linspace(0,V0,100);
for m=1:length(L)

a=1;
for c=1:length(steps)
x(c)=fsolve(@energy_new,steps(c));
if isreal(x(c))
REsim(a)=x(c);
a=a+1;
end
end


if isempty(REsim)==0
REsim=(round(REsim.*10000))./10000;
n=REsim(1);
j=1;
for i=2:length(REsim)
if REsim(i-1)~=REsim(i)
j=j+1;
n(j)=REsim(i);
end
end
REsim=[];
end
x=n;
mm=length(x);
for nn=1:mm
y(nn,l)=x(nn);
end





%yguess=0;
%y=findallzeros(@barrier,V0,5)
%y=fmin(@energy_new,0,V0)
%y(m)=fzero(@energy_new,[0 V0])
%y=fsolve(@energy_new,V0)
%root(m)=bisect(@energy_new,a,b,1e-6);

%if root(m)<b ;

%a=a+0.00001;
%root(m)=bisect(@energy_new,a,b,1e-6);
%x=root(m);
%else
% x=root(m);
%end


xlswrite('root.xls',L,'sheet1','A1')
xlswrite('root.xls',y,'sheet1','B1')

end



Thank you
George Veropoulos


Date Subject Author
12/22/11
Read fsolve
george veropoulos
12/22/11
Read Re: fsolve
John D'Errico

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.