Rella
Rella

Reputation: 66935

Maple: Why I can not plot my function which is definrd by proc?

So I created a proc that returns a value. (sqrt analog that is correct for numbers from (2.1) and up). I can evaluate it for any given number but I cannot plot it. Why and how to fix it?

enter image description here

code (converted to 1-d math input):

> 
restart:
 with(plottools):
val := 248;
sqr := proc (sqrtFrom, iterations) answer := 0; ampl := 0; number := sqrtFrom; for k to iterations do answer := 10*answer; number := sqrtFrom*10^ampl; for i from 0 while i < number do answer := answer+1; i := answer^2 end do; answer := answer-1; difr := -1; while difr < 0 do ampl := ampl+1; difr := sqrtFrom*10^ampl-100*answer^2 end do end do; return evalf(answer/10^(iterations-1)) end proc;
> 
evalf(sqrt(val));
sqr(val, 10);
plot(sqr(x, 10), x = 3 .. 5);
> 

Upvotes: 0

Views: 860

Answers (1)

Jacques Carette
Jacques Carette

Reputation: 3135

You need eval quotes. Try

plot('sqr'(x,10), x = 3..5 ); The error you get is because sqr is being called prematurely with x as an argument, and it can't do that.

Alternatively, you can modify sqr itself to return unevaluated if it gets non-numeric arguments (which is how sqrt works).

Upvotes: 1

Related Questions