Shading with vertical lines
Ältere Kommentare anzeigen
I'm trying to shade the region over which the integral extends with vertical lines. This is my integral:
F = @(x,y) x.*y;
ymin = @(x) x.^2;
ymax = @(x) x;
q = integral2(F,0,1,ymin,ymax)
The code below produces a graph with vertical line shading over its region. This is an example of what i'm trying to do.
f = @(x) sin(x + 1); g = @(x) x.^3 - 3*x + 1;
fplot(f, [-3, 3]), hold on
fplot(g, [-3, 3], 'LineWidth', 2)
>> x1 = fzero(@(x) f(x) - g(x), -2);
x2 = fzero(@(x) f(x) - g(x), 0);
x3 = fzero(@(x) f(x) - g(x), 2);
>> xcoord = linspace(x1, x3, 10);
ycoord = [f(xcoord); g(xcoord)];
plot([xcoord;xcoord], ycoord), hold off
5 Kommentare
Your code already works. What exactly is your issue?
(note that this code could be optimized to use a single line object, instead of having a separate object of every vertical line, but that doesn't affect the fundamental operation)
f = @(x) sin(x + 1); g = @(x) x.^3 - 3*x + 1;
fplot(f, [-3, 3]), hold on
fplot(g, [-3, 3], 'LineWidth', 2)
x1 = fzero(@(x) f(x) - g(x), -2);
x2 = fzero(@(x) f(x) - g(x), 0);
x3 = fzero(@(x) f(x) - g(x), 2);
xcoord = linspace(x1, x3, 100);
ycoord = [f(xcoord); g(xcoord)];
plot([xcoord;xcoord], ycoord,'k'), hold off
DGM
am 25 Apr. 2022
I'm pretty sure the second code block is an example of what OP wants to apply to the first code block.
Rik
am 25 Apr. 2022
The problem with the first block is that F is not a function of x, but of x and y, so the shading of the second block doesn't make sense, unless the function is converted to a function of x alone.
@Ikenna Iwudike Do you mean you want some sort of surface plot? The shading might be difficult to see.
Ikenna Iwudike
am 25 Apr. 2022
Rik
am 25 Apr. 2022
See if my edited answer works for you. The loop can be optimized to plot all stems as a single object, but I first wanted to create it like this.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Vehicle Scenarios finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


