equation in matlab
Hi everyone,
i have a difficult exercise in matlab and i need your help if anyone knows.
The idea of this exercise is to insert a theoretical equation Cdot in Matlab.With the results which it'll give me,i want to create a theoretical graph with axis x(v) and y(Cdot).Finally this graph i want to compare it with one experimental graph which i have.Summary,my goal is to find the best combination of ndot,M,edot in which the theoretical graph to be quite similar to experimental graph(sorry for my bad English).
The equation which i have is:
a=1/(1+exp((E - Vdot)/(k*T)))
b=(G*Ndot)/sqrt((pi*M)/2)
c=exp(-2((E + Edot + Vdot)/M)^2)
Cdot=q*A*L∂/∂v∫a*b*c dE
where Vdot=v/L and M=de(this name i gave it in my code).The integral i want to be [0,+inf] with respect to E.
The total equation which i want to insert in matlab is Total=Cdot1+Cdot2+C.
Cdot1,Cdot2 are 2 different distrubutions and
C=A*(sqrt((q*ep*e0*Nd)./(2*(Vbi-v-k*T))))
Now the code which i thought is:
Firstly,i make 2 m-files with names integral1,integral2 which has this function(everything i do here is the same with m-file integral2):
The 2nd code is an m-file with name derivative.
This is the huge code which i thought.Maybe when you see that you have headache.
But my really problem is how to calculate the integral and about that i need your help if anyone knows.
Thank You!!:)
i have a difficult exercise in matlab and i need your help if anyone knows.
The idea of this exercise is to insert a theoretical equation Cdot in Matlab.With the results which it'll give me,i want to create a theoretical graph with axis x(v) and y(Cdot).Finally this graph i want to compare it with one experimental graph which i have.Summary,my goal is to find the best combination of ndot,M,edot in which the theoretical graph to be quite similar to experimental graph(sorry for my bad English).
The equation which i have is:
a=1/(1+exp((E - Vdot)/(k*T)))
b=(G*Ndot)/sqrt((pi*M)/2)
c=exp(-2((E + Edot + Vdot)/M)^2)
Cdot=q*A*L∂/∂v∫a*b*c dE
where Vdot=v/L and M=de(this name i gave it in my code).The integral i want to be [0,+inf] with respect to E.
The total equation which i want to insert in matlab is Total=Cdot1+Cdot2+C.
Cdot1,Cdot2 are 2 different distrubutions and
C=A*(sqrt((q*ep*e0*Nd)./(2*(Vbi-v-k*T))))
Now the code which i thought is:
Firstly,i make 2 m-files with names integral1,integral2 which has this function(everything i do here is the same with m-file integral2):
function subtotal1=integral1(ndot1,de1,v1) A=12.56e-4; %this value is static,not change L=0.44; %this value is static,not change G=2; %this value is static,not change T=300.0; %this value is static,not change q=1.6e-19; %this value is static,not change k=8.62e-5; %this value is static,not change(Boltzman) Edot1=-0.3; %between -0.6-0.6 syms E; %(define) E a=1/(1+exp((E-(v/L))/(k*T))); b=(G*ndot1)./(sqrt((pi*de1)/2)); ek8eths1=((E+Edot1+(v/L))/de1).^2; c=exp(-2*ek8eths1); final1=a.*c*b; inline_final1 = vectorize (inline (char (final1))); subtotal1 = quad (inline_final1,0,1e13);My problem is the last 2 lines.I'm not sure if this is the best way to find the integral.Also,if i try quad (inline_final1,0,inf) then all the values are NaN.Why?
The 2nd code is an m-file with name derivative.
clear all clc A=12.56e-4; L=0.44; q=1.6e-19; ep=13; e0=8.85e-14; Nd=2e15; Vbi=2; k=8.62e-5; T=300.0; i=1; %1st distribution ndot1=3e10; de1=0.1; %2nd distribution ndot2=9e10; de2=0.1; v=-12:0.05:1.5; C=A*(sqrt((q*ep*e0*Nd)./(2*(Vbi-v-k*T)))); for i=1:1; for j=1:length(v) fintegrals1(j,i)=integral1(ndot1(i),de1(i),v(j)); fintegrals2(j,i)=integral2(ndot2(i),de2(i),v(j)); end end deriv1=-(diff(fintegrals1))./0.05; % (Q2-Q1)/(V2-V1) deriv2=-(diff( fintegrals2))./0.05; total1=deriv1.*(q*A*L); total2=deriv2.*(q*A*L); C=C.'; %1x280 to 280x1 totaly=C+total1+total2; path(path,'c:\thodoris') %here i have the experimental values load askisi2.txt plot(askisi2(:,1),askisi2(:,2),v,totaly) title('Ari8mitikh Epilisi') xlabel('V') ylabel('Col') legend('peiramatiki','8ewritiki')
This is the huge code which i thought.Maybe when you see that you have headache.
But my really problem is how to calculate the integral and about that i need your help if anyone knows.
Thank You!!:)
0
Comments
In the assignment: v is being used without being previously declared in the function. Pass it as input to the function if you need to use it.
In the assignment: Assuming del and ndot1 are vectors then it is more proper to write G.*ndot1 and pi.*del; as written this only works on row vectors (e.g. [a,b,c]) but not column vectors (e.g. [a;b;c]). Maybe not important here but later on you'll probably be working with equations that only hold when using column vectors.
In the assignment: v is being used without being previously declared in the function. Pass it as input to the function if you need to use it.
In the assignment: Again, check your element vs. vector operators. It's good practice to ALWAYS use element operators when you intend to do an element operations, even when the vectors are only a single element in length.
MATLAB has a symbolic integrator in the symbolic math toolkit. Since you're declaring E as a symbolic you will need to use the int() function. Read the help file for some hints about its usage or check the symbolic math toolbox manual. I'd be willing to bet your NaN problem stems from mixing symbolic math variables with numerical solvers.
In script derivative:
For the assignment Multi-element vector ranges should be assigned with brackets around them (v = [-12:0.05:1.5].)
For the assignment Every variable used here with the exception of v is used without having been previously assigned.
For the assignment You're using the diff() function from the symbolic math toolbox. You need to specify an additional argument containing the symbol you're differentiating with respect to (help diff for more).
For the assignment You can also write this as C=C';
Overall, if you have a MATLAB book that describes symbolic math you should probably review it. Also, you should review overall program structure especially defining constants at the beginning of your script. That way you're not digging through different functions checking to see if a constant you need is defined locally or not as well as making it easier for you to see all the constant data you're putting into your script for easy changes. For instance, most of the constant data defined in function integral should be defined as constants in script derivative since that data is used in both places.
-drasnor