How to show only parts of a function in a plot, in order to combine functions?

20 vues (au cours des 30 derniers jours)
Hi everyone,
I need some help with this. I got three functions, but I want to plot only part of them and stich them together. This is the code and the figure. So I want the blue line to go up to the intersection with the red line (1,0101,1,0203) and I want the other two plots to not show in this region. Then, from that intersection point, I want the red line to go up to the intersection (5,4545, 3,5692) while omiting the other functions in this interval and thirdly, after this interaction, I want the graph to show only the black line. Is that possible?
x=linspace(0,20)
y=x.^4.*exp(-x);
plot(x,y,'k')
grid on
hold on
y=x.^(3/4);
plot(x,y,'r')
axis([ 0 20 10^(-2) 10^2])
hold on
y=x.^2;
plot(x,y,'b')
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
  3 commentaires
Maxtron Moon
Maxtron Moon le 30 Juin 2020
It would look something like this (you know the units and curves are not the same) but basically I want to combine it in this way; the first interval would consist of the blue line, the second of the red and the last of the black line all stiched together to look like a single function)
darova
darova le 30 Juin 2020
Do you have this program?

Connectez-vous pour commenter.

Réponse acceptée

Kevin Joshi
Kevin Joshi le 30 Juin 2020
clc;
clear all;
%%
x=linspace(0,20);
y1=x.^4.*exp(-x);
y2=x.^(3/4);
y3=x.^2;
%%
x=linspace(0,20);
[x12,y12] = intersections(x,y1,x,y2,1)
[x23,y23] = intersections(x,y2,x,y3,1)
x3_3 = 0:0.0001:x23(2);
y3_3 = x3_3.^2;
p1 = plot(x3_3,y3_3,'b','LineWidth',1);
hold on
x2_2 = x23(2):0.0001:x12(3);
y2_2 = x2_2.^(3/4);
p2 = plot(x2_2,y2_2,'r','LineWidth',1);
x3_3 = x12(3):0.0001:20;
y3_3 = x3_3.^4.*exp(-x3_3);
p3 = plot(x3_3,y3_3,'k','LineWidth',1);
datatip(p3,x2_2(end),y2_2(end))
axis([10^-2 20 10^(-2) 10^2])
grid on;
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
I have used
to find line intersections.
  1 commentaire
Maxtron Moon
Maxtron Moon le 30 Juin 2020
Thank you very much! This is exactly what I been looking for! God bless...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Axes Appearance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by