Piecewise function in octave
Ben Abbott
bpabbott at mac.com
Wed Oct 15 17:54:43 CDT 2008
".*" is element by element multiplication, where "*" is matrix
multiplication.
f = @(t) a(t) .* (t<t0) + b(t) .* (t==t0) + c(t) .* (t>t0);
For example,
octave-3.1.51+:1> a = @(t) -1;
octave-3.1.51+:2> b = @(t) 0;
octave-3.1.51+:3> c = @(t) 1;
octave-3.1.51+:4> f = @(t,t0) a(t) .* (t<t0) + b(t) .* (t==t0) +
c(t) .* (t>t0);
octave-3.1.51+:5> t = (-10):10;
octave-3.1.51+:6> x = f(t,0);
octave-3.1.51+:7> x
x =
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 1 1 1 1 1
1 1 1 1 1
octave-3.1.51+:8> x = f(t,3)
x =
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 1 1
1 1 1 1 1
Ben
On Oct 15, 2008, at 5:42 PM, genehacker wrote:
>
> Hi Carlo,
>
> Can you please tell what .* do to the equation. Also how would
> you write
> a generalised piecewise function like
>
> f(t) = a(t) t < t0
> b(t) t = t0
> c(t) t > t0
>
> thanks in advance,
> k3.
>
>
> Carlo de Falco-2 wrote:
>>
>>
>> On 15/ott/08, at 21:57, genehacker wrote:
>>
>>> Hi,
>>>
>>> I am looking for a code that can specify a function f(t)
>>> piecewise, i.e.
>>> that can be defined according to intervals based on value of t. I
>>> want to
>>> integrate one of these in an anonymous function g(x,t).
>>>
>>> f(t) = sin(t) t<pi
>>> 0 t>=pi
>>>
>>> cheers
>>> k3
>>
>> to implement the example above you could use
>>
>> f = @(t) sin(t) .* (t<pi) ;
>>
>> c.
>>
>> _______________________________________________
>> Help-octave mailing list
>> Help-octave at cae.wisc.edu
>> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Piecewise-function-in-octave-tp20002314p20003062.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> Help-octave at cae.wisc.edu
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
More information about the Help-octave
mailing list