Single value after integration instead of matrix

Dear all,
I have a code as given below.
I want to integratethis function and in the end i want to have numeric matrix. But when i run the code i am getting single value. What i want is having a one-dimensional matrix, each row should be calculated from the integration.
When i run the code i am getting "0" as a result.
Normally z is step function with a intensity 0.228. Middle of z is 0 it gives a function like ;
In the end i assign z -> alfa*sin(wt) and want to integrate over t. I should have a matrix which should give sligtly different shape then given above (bended side trough the middle).
Please help....
Vb1=0.228; dz=1E-11;
Ltot = 20e-9;
z=-Ltot/2:dz:Ltot/2;
L = 10e-9; alfa=5e-9; w=1E+14; T=2*pi/w;
t= 0:T/(length(z)-1):T;
z =z + alfa.*sin(w.*t);
Vb =@(t) ((z<-L/2).*(Vb1) + (z>-L/2).*(Vb.*(z./(2*Ltot)+0.25)) + (z>L/2).*(Vb1));
V0 = (1/T).*integral(Vb,0,T)

댓글 수: 6

  1. The definition z =@(z,t) (z + alfa.*sin(w.*t)); will nowhere be used.
  2. Vb =@(z,t) ((z<-L/2).*(Vb1) + (z>-L/2).*0 + (z>L/2).*(Vb1)); can't be used as a function handle for "integral" since "integral" needs a function with only one input argument, not two.
  3. The spacings z=-Ltot/2:dz:Ltot/2; and t= 0:T/(length(z)-1):T; won't have any effect.
We still don't know what the function is you are trying to integrate.
Dear Torsten,
We can change the function as Vb =@(t) ((z<-L/2).*(Vb1) + (z>-L/2).*(Vb.*(z./(2*Ltot)+0.25)) + (z>L/2).*(Vb1));
Vb =@(t) ((z<-L/2).*(Vb1) + (z>-L/2).*(Vb.*(z./(2*Ltot)+0.25)) + (z>L/2).*(Vb1));
The previous one is the simplest one.
As you ask, when i change the function, it is givinf error too.
What is z ? As written, MATLAB expects a single, previously defined value for it.
Özgür Alaydin
Özgür Alaydin 2022년 2월 24일
편집: Özgür Alaydin 2022년 2월 24일
z is as written. It is matrix. i assign z as z+sin(wt).
So the function Vb is z and t dependent. I need to integrate for t but V0 must be matrix same size with z.
Torsten
Torsten 2022년 2월 24일
편집: Torsten 2022년 2월 24일
If you set z = z + alfa.*sin(w.*t), z is an array of values - the integration variable t has disappeared.
So Vb does no longer depend on t.
Maybe you want this:
Vb1=0.228; dz=1E-11;
Ltot = 20e-9;
z=-Ltot/2:dz:Ltot/2;
L = 10e-9; alfa=5e-9; w=1E+14; T=2*pi/w;
for i=1:numel(z)
fz =@(t) z(i) + alfa.*sin(w.*t);
Vb = @(t) ((fz(t)<-L/2).*(Vb1) + (fz(t)>-L/2).*(Vb1.*(fz(t)./(2*Ltot)+0.25)) + (fz(t)>L/2).*(Vb1));
V0(i) = (1/T).*integral(Vb,0,T,'ArrayValued',true)
end
Dear Torsten
Thanks a lot.
This is exactly what i want. I have learnt one more command (numel).
Regards.

댓글을 달려면 로그인하십시오.

 채택된 답변

Özgür Alaydin
Özgür Alaydin 2022년 3월 5일

0 개 추천

Vb1=0.228; dz=1E-11;
Ltot = 20e-9;
z=-Ltot/2:dz:Ltot/2;
L = 10e-9; alfa=5e-9; w=1E+14; T=2*pi/w;
for i=1:numel(z)
fz =@(t) z(i) + alfa.*sin(w.*t);
Vb = @(t) ((fz(t)<-L/2).*(Vb1) + (fz(t)>-L/2).*(Vb1.*(fz(t)./(2*Ltot)+0.25)) + (fz(t)>L/2).*(Vb1));
V0(i) = (1/T).*integral(Vb,0,T,'ArrayValued',true)
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by