cancel
Showing results for 
Search instead for 
Did you mean: 
kervanoel
New member
2 1 0 0
Message 1 of 4
1,011
Flag Post

Solved!

CAS programs

HP Recommended
HP PRIME
macOS 10.12 Sierra

I am a beginner.

Have you an example for CAS programation? i have tried this program:

 

#cas

QQQQ():=

BEGIN

LOCAL f,g;

INPUT(f);

g:=laplace(f,x);

return (g)

END

#end

 

When i verif its ok but when i exec it doesn't work.

 

Thank you very much for your help

 

0 Kudos
3 REPLIES 3
Jan_D
Level 6
305 297 32 76
Message 2 of 4
Flag Post
HP Recommended

First, you should not forget semicolons after return(g) and END.

 

Next, you can not use the INPUT command in CAS programs.

 

Instead of a CAS program you could write a non-cas program as follows:

 

EXPORT QQQQ()

BEGIN

LOCAL f,g;

INPUT({{f,[2]}});

g:=CAS.laplace(EVAL(f),”x”);

return (g);

END;

 

I realize that this is a bit complicated.

 

Some remarks:

Notice the double curly brackets in the input command.

This construction is necessary because the input will be a string.

 

{f,[2]} means that f is a string.

You should enter your function in lowercase, e.g sin(x), because symbolic calculations in CAS are done in lowercase.

 

Suppose you wanted to use the laplace command in a non-cas program for the function sin(x), then you could write: CAS.laplace(“sin(x)”,”x”).

 

Notice the quotation marks.

So it would be logical to write in our program: CAS.laplace(f,“x”), because f is a string.

 

But because of some reason this is not possible when f is a variable which contains a string, and in such a case we have to write: CAS.laplace(EVAL(f),”x”).

 

Also read:

http://www.hpmuseum.org/forum/thread-216.html

http://www.hpmuseum.org/forum/thread-215.html

http://www.hpmuseum.org/forum/thread-3149.html

 

 

 

 

 

 

 

 

 

kervanoel
Author
New member
2 1 0 0
Message 3 of 4
Flag Post
HP Recommended

Thanks a lot for your answer.

Is there a book or a link for CAS programming, because it seems it is slighty different?

All is ok now. What is the meaning of # created by HP Prime for new CAS programs?

 

0 Kudos
Jan_D
Level 6
305 297 32 76
Message 4 of 4
Flag Post
HP Recommended

I do not know if there is a book about CAS programming.

 

The online user guide is quite good, but when you want to write more complicated programs it is insufficient, and you have to look for more information elsewhere.

 

In this forum you can ask questions.

 

Also here: http://www.hpmuseum.org/forum/forum-5.html

 

The third link I gave, by Han, gives some important information concerning CAS programming. Only do not forget the trick with EVAL which I showed in my previous post.

 

By the way, the most powerful and general way to use CAS - commands in non - CAS programs is, when we stay with the example of laplace(f,x), to write it as CAS(“laplace(f,x)”).

 

Here f could be sin(x), so not a string.

 

Suppose we have f in the form of a string, like it is given by the INPUT command, and let’s call it f_s, so

f_s=”sin(x)”.

 

Then we can write the argument of CAS(“laplace(f,x)”), which is “laplace(f,x)” as the sum of 3 strings, namely “laplace(f,x)”= “laplace(“  +   "f"   +    ”,x)”.

(So  “laplace(“ is the first string, "f" the second, and  ”,x)” the third)

 

Because “f”=f_s:

 

“laplace(f,x)”= “laplace(“   +   f_s   +   ”,x)”

 

We can now define r as

r:= “laplace(“   +   f_s   +   ”,x)”

 

And our command will be: CAS(EVAL(r))

 

This is also explained by Han.

 

Maybe you can find more information by looking for Xcas/Giac, because the Prime’s CAS is based upon this.

 

The construction with # ’s only serves to discern between a CAS program and a non CAS program.

 

It is of course most easy to not use the INPUT command at all, then we can confine ourselves to a simple CAS program:

 

#cas

QQQQ(a,b):=

BEGIN

LOCAL g; 

g:=laplace(a,b);

return (g);

END;

#end

 

 

0 Kudos
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation