[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Piecewise function in octave
From: |
fBacani |
Subject: |
Re: Piecewise function in octave |
Date: |
Tue, 26 Apr 2011 12:50:12 -0700 (PDT) |
Guys, thank you so much for this thread!
I've implemented a triangular function using this idea, here's the code:
fC= @(x,a,b) (x-a)/(b-a);
fD= @(x,b,c) (c-x)/(c-b);
f2= @(x,a,b,c) fC(x,a,b) .* (x < b) + 1 .* (x==b) + fD(x,b,c) .* (x>b);
f1= @(x,a,b,c) 0 .* (x<a) + f2(x,a,b,c) .* (x>a);
f = @(x,a,b,c) f1(x,a,b,c) .*(x<c) + 0 .* (x>c);
mesh = @(a,c) [a-1:.1:c+1]
triang = @(a,b,c) plot(mesh(a,c),f(mesh(a,c),a,b,c));
The triangular function below:
http://octave.1599824.n4.nabble.com/file/n3476357/Captura_de_tela.png
was generated calling "triang(1,2,4)".
Cheers,
Felipo
--
View this message in context:
http://octave.1599824.n4.nabble.com/Piecewise-function-in-octave-tp1633239p3476357.html
Sent from the Octave - General mailing list archive at Nabble.com.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Piecewise function in octave,
fBacani <=