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

8 visualizaciones (últimos 30 días)
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 comentarios
Maxtron Moon
Maxtron Moon el 30 de Jun. de 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)

Iniciar sesión para comentar.

Respuesta aceptada

Kevin Joshi
Kevin Joshi el 30 de Jun. de 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.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by