intrgartion_problem..
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
John D'Errico
on 1 Sep 2016
Edited: John D'Errico
on 1 Sep 2016
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 Comments
Walter Roberson
on 1 Sep 2016
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 );
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!