How can I connect the upper endpoint of the red curve to the red dot while keeping the curvature nearly the same?

1 visualización (últimos 30 días)
How can I connect the upper endpoint of the red curve to the red dot while keeping the curvature nearly the same?
clear all
format long
warning off
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20),x(325,1:idx-20),'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')

Respuesta aceptada

Star Strider
Star Strider el 8 de Jun. de 2024
Here are options using pchip, makima and spline
clear all
format long
warning off
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20),x(325,1:idx-20),'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
% line_end = [x(326,idx-20),x(325,idx-20)];
line_end = [x(326,idx-21:idx-20);x(325,idx-21:idx-20)];
scatter_point = [0.174701,0.17761];
connecting_line(1,:) = linspace(line_end(1), scatter_point(1), 150);
connecting_line(2,:) = pchip([line_end(1,:) scatter_point(1)], [line_end(2,:) scatter_point(2)], connecting_line(1,:));
plot(connecting_line(1,:), connecting_line(2,:),'r', 'LineWidth',2);
title('Using ‘pchip’')
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20),x(325,1:idx-20),'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
% line_end = [x(326,idx-20),x(325,idx-20)];
line_end = [x(326,idx-21:idx-20);x(325,idx-21:idx-20)];
scatter_point = [0.174701,0.17761];
connecting_line(1,:) = linspace(line_end(1), scatter_point(1), 150);
connecting_line(2,:) = makima([line_end(1,:) scatter_point(1)], [line_end(2,:) scatter_point(2)], connecting_line(1,:));
plot(connecting_line(1,:), connecting_line(2,:),'r', 'LineWidth',2);
title('Using ‘makima’')
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20),x(325,1:idx-20),'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
% line_end = [x(326,idx-20),x(325,idx-20)];
line_end = [x(326,idx-21:idx-20);x(325,idx-21:idx-20)];
scatter_point = [0.174701,0.17761];
connecting_line(1,:) = linspace(line_end(1), scatter_point(1), 150);
connecting_line(2,:) = spline([line_end(1,:) scatter_point(1)], [line_end(2,:) scatter_point(2)], connecting_line(1,:));
plot(connecting_line(1,:), connecting_line(2,:),'r', 'LineWidth',2);
title('Using ‘spline’')
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
This uses the last two points of the red line so that the interpolation functions can use that slope information as well. That is straightforward to expand if necessary. The original (and now commented-out) vales for ‘line_end’ used only the last point.
Zoom in on these to see which works best for you.
.

Más respuestas (1)

Image Analyst
Image Analyst el 8 de Jun. de 2024
Try using plot after you use scatter to draw a line from the last point on the curve to the marker you placed with scatter():
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>curve_func
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>defaultprocessor
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>options
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>jacobian
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>hessians
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>testf
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>userf
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>process
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>singmat
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>locate
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>init
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>done
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Homoclinic\homoclinic.m>adapt
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\sudeshna_3.m>fun_eval
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\sudeshna_3.m>jacobian
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\sudeshna_3.m>jacobianp
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\sudeshna_3.m>hessians
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\sudeshna_3.m>hessiansp
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\sudeshna_3.m>der3
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\GUI\ComputationConfigurations\ContCurve.m>@(dat)loaderfunction(dat)
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20), x(325,1:idx-20), 'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
xTip = [x(326,1:idx-20), 0.174701];
yTip = [x(325,1:idx-20), 0.177614];
plot(xTip, yTip, 'r-', 'LineWidth', 2);
grid on;
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
There will be a slight change in curvature. It it's really objectionable, you can use the scatter point and the last two points of the curve and fit a cubic to it and interpolate a bunch of points in between. Not sure it would look much different though than the straight line.
  3 comentarios
Image Analyst
Image Analyst el 8 de Jun. de 2024
Editada: Image Analyst el 8 de Jun. de 2024
As you can see, Star used some more sophisticated methods and the plot looks virtually the same. Are they still not good enough? Is so, why not? What is the purpose of the plot? Who is the consumer/viewer of these plots and will they be annoyed if it's not smoother?
But realize that as the final point gets much further away, the connecting curve will have to look more and more like a line. I mean if the point was out at 0.4 or 0.5, what would you expect the connecting curve to look like? It can't be very curvy!

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by