필터 지우기
필터 지우기

intrgartion_problem..

조회 수: 1 (최근 30일)
george veropoulos
george veropoulos 2016년 9월 1일
댓글: John D'Errico 2016년 9월 1일
Hi im trying to run a code i call in some point the folllow lines
y_theory=@(t)((1./(P.*Zl)).*f_xi(t./(Zl*P)))./(g_norm);
x=0:1e-6:V2L;
yi=@(x)integral(y_theory,0,x,'ArrayValued',true)
plot(x,yi(x),'r','LineWidth',2)
xlabel('|V_{L}|(V)')
ylabel('f(|V_{L}|)(1/v)')
and i recieve the message
Error using integral (line 86)
A and B must be floating point scalars.
Error in @(x)integral(y_theory,0,x,'ArrayValued',true)
Error in main_distr_polarization4VL_cum (line 160)
plot(x,yi(x),'r','LineWidth',2)
what is the problem?
thank you in advance George

답변 (1개)

John D'Errico
John D'Errico 2016년 9월 1일
편집: John D'Errico 2016년 9월 1일
integral does not have the capability to solve a problem with multiple limits of integration. The help never states that the limits of integration can be anything other than a scalar value.
The arrayvalued flag is not designed to solve arrays of limits, but array valued functions! There is a big difference. From the help for integral:
'ArrayValued', FUN is an array-valued function when the input is scalar
That you want it to work in away that it is not designed to work is not relevant. Of course, nothing stops you from using a loop to accomplish this task. You can even make it efficient. Thus...
Since x is the upper limit of integration, and x varies as
x=0:1e-6:V2L;
then use integral to compute the integral between each increment in x, then use cumsum to compute the cumulative integral. This avoids forcing integral to compute the integral of the same region multiple times.
Sometimes a loop is the simplest solution. But assuming that code will somehow magically know what it is that you wanted to do is rarely the correct approach.
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 9월 1일
y_theory=@(t)((1./(P.*Zl)).*f_xi(t./(Zl*P)))./(g_norm);
x=0:1e-6:V2L;
yi_parts = arrayfun( @(idx) integral(y_theory, x(idx), x(idx+1)), 1:length(x)-1 );
yi = cumsum( yi_parts );
John D'Errico
John D'Errico 2016년 9월 1일
Walter has it right. Though it could be done using a loop too.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by