Plot integral of a function
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I'm tryign to plot the integral of the function rho in the following code, but I'm having trouble with plotting it. Perhaps anyone can help me with the code for plotting the integral of this rho function in the different areas? This is what I've tried:
q = 1.5*10^-16;
a = 1;
Na = 10^16;
xn = 3;
xp = -2;
rho_righ = @(x) a.*x;
rho_left = @(x) -q*Na;
nop = @(x) 0;
figure(1);
fplot(rho_righ, [0,xn]);
hold on;
fplot(rho_left, [xp,0]);
hold on;
fplot(nop, [-5,xp]);
hold on;
fplot(nop, [xn,5]);
grid on;
legend('{\rho}=qax','{\rho}=-qNa');
hold off;
upper_limit = linspace(-xp, 0);
upper_limit2 = linspace(0, xn);
xval = arrayfun(@(uplim) integral(rho, 0, uplim, 'ArrayValued',true), upper_limit);
xval2 = arrayfun(@(uplim) integral(rho, 0, uplim, 'ArrayValued',true), upper_limit2);
figure(2)
plot(upper_limit, xval);
hold on;
plot(upper_limit2, xval2);
grid on;
Thank you very much!
댓글 수: 0
채택된 답변
Star Strider
2020년 12월 27일
The problem appears to be that ‘rho’ itself does not exist.
I have no idea what you want ‘rho’ to be, however defining it as:
rho = @(x) rho_left(x) .* (x <= 0) + rho_righ(x) .* (x > 0);
will likely be an appropriate place to begin, and that produces figure(2) (and myriad Warning messages).. Whatever you intend it to be, it needs to be defined.
댓글 수: 4
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!