Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. %constants
  2. h2=1.05e-34;
  3. mass=9.11e-31;
  4. a=5.51e-10;
  5. p=11;
  6. Emax=100*1.6e-19;
  7. %Figure(4) using the K in the last question
  8. E=linspace(0,3e-19,1000);
  9. alpha=sqrt(2*mass*E)/h2;
  10. LHS=((p/a)*sin(alpha*a)./alpha)+cos(alpha*a);
  11. k=acos(LHS)./a;
  12. %first derivative
  13. dy=diff(E)./diff(k);
  14. dy=[min(dy),dy];
  15. %second derivative
  16. dyy=diff(dy)./diff(k);
  17. dyy=[max(dyy),dyy];
  18. %effective mass
  19. eff_mass=(h2^2)./dyy;
  20. %plotting two curve the positive and the negative
  21. plot(k,eff_mass,-k,eff_mass);
  22.  
  23. %part 2
  24. %taking the equation from the user
  25. sc = inputdlg('Type an expression that is a function of ‘k’:' ); % Cell Output
  26. k1= sc{:}; % Function String
  27. k_fun= str2func(['@(k)' k1]) ; % Not Vectorized (Illustration Only)
  28. k_funv= str2func(['@(k)' vectorize(k1)]);
  29. %first derivative
  30. first=diff(k_funv(k))./diff(k);
  31. first=[max(first),first];
  32. %second derivative
  33. second=diff(first)./diff(k);
  34. second=[min(second),second];
  35. %effective mass
  36. eff_mass2=(h2^2)./second;
  37. plot(k,eff_mass2,(-1)*k,eff_mass2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement