필터 지우기
필터 지우기

error using integral function

조회 수: 7 (최근 30일)
nune pratyusha
nune pratyusha 2021년 4월 29일
댓글: Jan 2021년 4월 29일
clc
clear all
close all
a=7.2*10^-6;
Gm=2.5*10^-2;
b=4.7;
sp=2.75*10^-5;
yon=6*10^-2;
son=4.5*10^-1;
B=10^-4;
A=10^-10;
soff=1.3*10^-2;
beta=500;
yoff=1.3*10^-2;
t=0:0.001:0.007;
vm=0.1:0.001:0.107;
gp=tanh(vm);
f=145;
v=sawtooth(2*pi*f*t);
y=(yon^2*(Gm-a*exp(b*sqrt(gp))).*v.^2)/(2*sp);
i=v.*(y*Gm+(1-y)*a.*(Gm-a*exp(b*sqrt(gp))));
Q145=integral(@(t) i,0,0.5);
error is comin like
Error using integralCalc/finalInputChecks (line 526)
Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued'
option to true.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in Untitled7 (line 22)
Q145=integral(@(t) i,0,0.5);
>>

답변 (2개)

Jan
Jan 2021년 4월 29일
편집: Jan 2021년 4월 29일
You do not integrate a function, but a vector:
i = v.*(y*Gm+(1-y)*a.*(Gm-a*exp(b*sqrt(gp))));
Q145=integral(@(t) i,0,0.5);
i is not a function depending on the input t, but a vector. Use trapz for integrating vectors.
By the way, the old brute clearing header "clc; clear all; close all" is a waste of time only. clear all removes all loaded frunction from the memory and reloading them from the slow disk takes time without any benefit. Use functions to keep the workspace clean.
Run time is not a point of your problem. But for real application prefer the cheap constand 7.2e-6 instead of the expensive power operation 7.2*10^-6.
  댓글 수: 3
nune pratyusha
nune pratyusha 2021년 4월 29일
but in directly i is depending on t because v is depending on t and y is depending on v
Jan
Jan 2021년 4월 29일
t = 0:0.1:1;
y = sin(t);
Now y is a constant, which does not depend on t anymore. See:
t = 27;
y % Of course this does not change its value
A function depending on a variable looks like this:
f = @(t) sin(t)
% Test it:
f(1)
f(2)

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


Star Strider
Star Strider 2021년 4월 29일
but in directly i is depending on t because v is depending on t and y is depending on v
True, however integral has no way of knowing that unless you tell it!
Try this —
format long g
a=7.2*10^-6;
Gm=2.5*10^-2;
b=4.7;
sp=2.75*10^-5;
yon=6*10^-2;
son=4.5*10^-1;
B=10^-4;
A=10^-10;
soff=1.3*10^-2;
beta=500;
yoff=1.3*10^-2;
% t=0:0.001:0.007;
vm=0.1:0.001:0.107;
gp=tanh(vm);
f=145;
v = @(t) sawtooth(2*pi*f*t);
y = @(t) (yon^2*(Gm-a*exp(b*sqrt(gp))).*v(t).^2)/(2*sp);
i = @(t) v(t).*(y(t)*Gm+(1-y(t))*a.*(Gm-a*exp(b*sqrt(gp))));
Q145=integral(i,0,0.5, 'ArrayValued',1)
Q145 = 1×8
-3.53002158342886e-05 -3.52998846582496e-05 -3.52995527482942e-05 -3.52992200995947e-05 -3.52988867074367e-05 -3.52985525672159e-05 -3.52982176744341e-05 -3.5297882024696e-05
figure
plot(vm, Q145)
grid
I will let you figure out how it wworks!

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by