[Top][All Lists]

[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&lt;a)   + f2(x,a,b,c) .* (x&gt;a);
f = @(x,a,b,c) f1(x,a,b,c) .*(x&lt;c) + 0 .* (x&gt;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: 
was generated calling "triang(1,2,4)".


View this message in context:
Sent from the Octave - General mailing list archive at

reply via email to

[Prev in Thread] Current Thread [Next in Thread]