Plot integral of a function
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Elinor Ginzburg
am 27 Dez. 2020
Kommentiert: Star Strider
am 28 Dez. 2020
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 Kommentare
Akzeptierte Antwort
Star Strider
am 27 Dez. 2020
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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!