find a geodesic for the metric m between points x1 and x2 in matlab

To find a geodesic for the metric m between points x1 and x2 in MATLAB, you can use the funm function to compute the matrix exponential of the metric multiplied by the path length. Here's the code:

main.m
% Define the metric (as a 2x2 matrix-valued function)
m = @(x) [1/(1+x(2)^2), 0; 0, 1];

% Define the starting and ending points
x1 = [-1; 0];
x2 = [1; 0];

% Define the path length (as a scalar-valued function)
L = @(t) sqrt(sum((x2-x1).^2)) * t;

% Compute the geodesic
geo = @(t) expm(L(t)*m(x1)) * x1;

% Plot the geodesic
tvals = linspace(0, 1, 100);
plot(geo(tvals(1)), geo(tvals(2)), '.-', 'LineWidth', 2)
413 chars
17 lines

In this code, m is the metric function, which is assumed to be a 2x2 matrix-valued function of the position vector x. x1 and x2 are the starting and ending points of the geodesic, respectively. L is the path length as a function of t (where 0<=t<=1), which is defined as the Euclidean distance between x1 and x2 multiplied by t. Finally, geo is the geodesic as a function of t, which uses the expm function to compute the matrix exponential of the metric times the path length, evaluated at x1. The resulting geodesic is then plotted using the plot function.

related categories

gistlibby LogSnag