From: Luca Turchet on 8 May 2010 12:10 Hi all, I think I got it. Please have a look and let me know what do you think: I define a file gaussian.m: function [f] = gaussian(x, m, s) a = 1/sqrt(2*pi*s); y = (x - m)/s; f = a*exp(-y.^2/2); and a file gaussian_der.m: function [dfdx] = gaussian_der(x, m, s) a = 1/sqrt(2*pi*s); y = (x - m)/s; f = a*exp(-y.^2/2); dfdx = -y.*f/s; Then I use the following procedure: %Point A coordinates A_x = -15; A_y = gaussian(A_x, m, s); m = 0;%mu s = 2;%sigma step_increment = 0.01; X = [A_x:step_increment:15]; distance_integral = sqrt(1 + gaussian_der(X, m, s).^2); Z = cumtrapz(X,distance_integral) distance = 10;% wanted distance from A to B index = find(Z>distance & Z < distance + step_increment) B_x = X(index) B_y = gaussian(B_x, m, s) %PLOT Y = gaussian(X, m, s); plot(X,Y) hold on; plot(A_x,A_y,'ro'); plot(B_x,B_y,'k*'); hold off; What do you think? It seems correct to me. Let me know! Best regards "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hs3lej$6jj$1(a)fred.mathworks.com>... > Here is the function that computes 1D gaussian pdf and its derivative > > function [f dfdx] = gaussian(x, m, s) > > a = 1/sqrt(2*pi*s); > y = (x - m)/s; > f = a*exp(-y.^2/2); > dfdx = -y.*f/s; > > end
From: Bruno Luong on 8 May 2010 15:08 "Luca Turchet" <tur(a)imi.aau.dk> wrote in message <hs42df$eo0$1(a)fred.mathworks.com>... > index = find(Z>distance & Z < distance + step_increment) I think such test is unreliable for many reasons. I let you think why. Bruno
From: Luca Turchet on 8 May 2010 15:41 Hi Bruno, to be honest I tried to understand why it is not correct. I only get to the conclusion that it is as imprecise as the number of points with which I divide the distance decrease. What do you suggest? Any proposal? Thanks Luca "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hs4cqk$b6a$1(a)fred.mathworks.com>... > "Luca Turchet" <tur(a)imi.aau.dk> wrote in message <hs42df$eo0$1(a)fred.mathworks.com>... > > > index = find(Z>distance & Z < distance + step_increment) > > I think such test is unreliable for many reasons. I let you think why. > > Bruno
From: Roger Stafford on 8 May 2010 15:41 "Luca Turchet" <tur(a)imi.aau.dk> wrote in message <hs42df$eo0$1(a)fred.mathworks.com>... > Hi all, > I think I got it. > ....... I think you should follow John's excellent advice, Luca. It sounds the best to me, since you have a curve y = f(x) with a known formula for its derivative, f'(x). The differential equation you would be solving with 'ode45' is: dx/ds = 1/sqrt(1+f'(x).^2) . You integrate with respect to arc length s as your independent variable, starting with x as the x-coordinate of point A at s = 0, and you stop when s has reached the distance you wish to travel along the curve to point B. What could be simpler? Roger Stafford
From: Bruno Luong on 8 May 2010 16:02 "Luca Turchet" <tur(a)imi.aau.dk> wrote in message <hs4eof$dhe$1(a)fred.mathworks.com>... > What do you suggest? Any proposal? Sometime this test would return empty, especially when the function has a large slope. Bruno
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: distance between two points along a curve Next: Matlab Engine Can't Open..... |