gst

10 Reputation

One Badge

2 years, 294 days

MaplePrimes Activity


These are questions asked by gst

If I have some similar functions, say sin(x), sin(2x)..., what approach is better:

f(i,x):=(i,x)->sin(i*x)

or

f[i](x):=x->sin(i*x)

?

Or maybe there is another way?

The second one seems more natural for me but  I've stucked with an error:

 

divide5.mw
 

NULLNULL

restart; divide5 := proc (f) local x, r; r := unapply((1/5)*f(x), x); eval(r) end proc; f := proc (x) options operator, arrow; x^2 end proc; f := divide5(f); f(3)

9/5

(1)

restart; divide5 := proc (f) local i, x, r; r := unapply((1/5)*f(i, x), i, x); eval(r) end proc; f := proc (i, x) options operator, arrow; x^2+i end proc; f := divide5(f); f(5, 3)

14/5

(2)

restart; divide5 := proc (f) local x, r; r := unapply((1/5)*f(x), x); eval(r) end proc; f[i] := proc (x) options operator, arrow; x^2+i end proc; f[5] := divide5(f[5]); f[5](3)

Error, (in f[5]) too many levels of recursion

 

NULL


 

Download divide5.mw

 


What's the matter?

Thank you for your answers.

 

The input

f(x) := x^2;

n := evalf(int(f(x)^2, x = 0 .. 1));

f(x) :=  f(x)/n;

plot(f(x), x = 0 .. 1)

leads to the error

Error, (in f) too many levels of recursion
I need to reassign the function as itself divided by n that depends on the old f...

A piece of code like this is supposed to be inside a loop, so creating f_new(x):=f(x)/n doesn't solve the issue.

If it was a cpp code I'd write something like f(x)/=n for every x. How can I do it in Maple?

Thank you in advance for you answers!

Page 1 of 1