Symbolic entry of rem function

When entering the following symbolic code using the remainder (rem) function, Matlab returns x(t,P) = 0, which is clearly wrong.
syms t P
x(t, P) = rem(t,P);
x
I have tried all combinations of sym, syms, symfun, but the result is the same. I need to enter the symbolic function x = rem(t,P) to perform symbolic integration on it over the period t = [0:P].
Help is appreciated, thanks

 Risposta accettata

Wrong function. Use mod instead for symbolic operations:
syms t P
x(t, P) = mod(t,P);
x
returns:
x(t, P) =
t*(1 mod P)

5 Commenti

Nate
Nate il 28 Set 2014
There is one problem: when t = P or t > P, it breaks down:
syms t P
x(t, P) = mod(t, P);
x(0,2) returns 0 (correct)
x(1,2) returns 1 (correct)
x(2,2) returns 2 (incorrect)
x(3,2) returns 3 (incorrect)
Correct values:
rem(2,2) or mod(2,2) should equal 0
rem(3,2) or mod(3,2) should equal 1
Any other suggestions?
Star Strider
Star Strider il 28 Set 2014
Modificato: Star Strider il 28 Set 2014
It works if you just use the mod function directly:
syms t P
m1 =mod(0,2)
m2 =mod(1,2)
m3 =mod(2,2)
m4 =mod(3,2)
produces:
m1 =
0
m2 =
1
m3 =
0
m4 =
1
EDIT — Added:
It also works if you define your own function for mod:
syms t P
x = symfun(t-floor(t/P)*P, [t P]);
m1 =x(0,2)
m2 =x(1,2)
m3 =x(2,2)
m4 =x(3,2)
The result is as m1...m4 using the built-in mod function, so I won’t repeat them.
Nate
Nate il 28 Set 2014
Brilliant, thanks so much.
My pleasure!
It was a fun challenge for me!
DmArcher
DmArcher il 24 Apr 2017
When I type your code I get some errors. Is it possible that you can tell me where I did it wrong? Thx.

Accedi per commentare.

Più risposte (0)

Richiesto:

il 27 Set 2014

Commentato:

il 24 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by