Post Reply 
[1/2 SOLVED] New FW10077 problem-CAS command in program context
04-22-2016, 11:08 AM (This post was last modified: 04-23-2016 11:28 AM by dg1969.)
Post: #1
[1/2 SOLVED] New FW10077 problem-CAS command in program context
Hi,

My last post diverge in another direction so I try a second chance...

If one of you have a little time...

You will find here a copy of a custon application for Bode plot (based on function app) that was working perfectly in the previous FW...

In the symb view, place one or more transfert function in term of X. Example: 1/(1+X) then press "plot key" and choose 1)module (magnitude) => works as usual;
repress "symb key" then "plot key" again: the two other options (phase and step response fails)...

1) All this happens as if certain rules were changed when it comes to use the CAS command in a program...

As an exemple in my code in the "calcule_phase()" function these lines now fails
Code:

f:="1/(1+x)";
denomi:=string(CAS.denom(f));

or these one :
Code:

a:=CAS.froot(f,"x");

2) Despite the pragma command, the compilation fails on the line:
Code:

a:=CAS.froot(f,"x");
when the digital grouping is set on 123 456,789

Really need help... Hp team ? Is there are some changes not yet documented for the CAS command use in program ?

Thank you for your time.


Attached File(s)
.zip  Bode.hpappdir.zip (Size: 4.38 KB / Downloads: 3)
Find all posts by this user
Quote this message in a reply
04-22-2016, 03:37 PM (This post was last modified: 04-22-2016 03:40 PM by Tim Wessman.)
Post: #2
RE: New FW10077 problem-CAS command in program context
Still looking at it...

I think you may have found a problem with the CAS evaluating a string in the numer/denom though, but that doesn't explain some of the others.

Basically though, we were trying to eliminate the need for strings to pass things to the CAS, and make variables (including local variables) work properly as expected.

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
04-22-2016, 03:53 PM
Post: #3
RE: New FW10077 problem-CAS command in program context
(04-22-2016 03:37 PM)Tim Wessman Wrote:  I think you may have found a problem with the CAS evaluating a string in the numer/denom though, but that doesn't explain some of the others.

Basically though, we were trying to eliminate the need for strings to pass things to the CAS, and make variables (including local variables) work properly as expected.

thank you very much Tim for your answer . I'll wait until a solution is proposed. This does not bother me. I do not think we can expect a compatibility at this point. It is obviously desirable that the functionality evolve towards greater consistency and simplicity. "Bravo" ! for this work and thank you for your help.

And what about pragma issue ?
Find all posts by this user
Quote this message in a reply
04-22-2016, 05:20 PM
Post: #4
RE: New FW10077 problem-CAS command in program context
Basically, calls using "CAS.<func>" no longer auto-evaluate the first argument. The reason for this is that you can now store and use local variables directly. Auto-evaluating would make that impossible.

When you have a string you'd like to evaluate *before* your CAS call, put in the EVAL function.

CAS.numer(f,"x"); ----> CAS.numer(EVAL(f),"x");

Before, that EVAL always happened no matter what. Now, you need to manually do it.

Code:
#pragma mode( separator(.,;) integer(h32) )

copie_les_fonctions();
replace_les_fonctions();
place_les_modules();
place_les_phases();
place_les_rep_temp();
calcule_modules();
calcule_phases();
calcule_rep_temp();
Symb();

export liste_fonctions:=MAKELIST(0,X,1,10);
export liste_modules:={};
export liste_phases:={};
export liste_rep_temp:={};
recalc_module:=MAKELIST(1,X,1,10);
recalc_phase:=MAKELIST(1,X,1,10);
recalc_temp:=MAKELIST(1,X,1,10);
modif:=1;

copie_les_fonctions()
begin
  local k;
  for k from 1 to 10 do
    if ISCHECK(k MOD 10) then
      if EVAL(EXPR("F"+k MOD 10)≠liste_fonctions(k)) then
        IFERR liste_fonctions(k):=EXPR("F"+k MOD 10) then MSGBOX("Erreur de copie sur F"+k MOD 10) end;
        recalc_module(k):=1;
        recalc_phase(k):=1;
        recalc_temp(k):=1; 
      end; 
    end;
  end;
  modif:=0;
end;

replace_les_fonctions()
begin
  local k;
  for k from 1 to length(liste_fonctions) do
    if ISCHECK(k MOD 10) then  
      expr("F"+k MOD 10+":=liste_fonctions("+k+")");
    end;
  end;
end;

place_les_modules()
begin
  local k;
  for k from 1 to length(liste_modules) do
     if ISCHECK(k MOD 10) then 
       expr("F"+k MOD 10+":=liste_modules("+k+")");
     end;
  end;
end;

place_les_phases()
begin
  local k;
  for k from 1 to length(liste_phases) do
     if ISCHECK(k MOD 10) then
       expr("F"+k MOD 10+":=liste_phases("+k+")");
     end;
  end;
end;

place_les_rep_temp()
begin
  local k;
  for k from 1 to length(liste_rep_temp) do
     if ISCHECK(k MOD 10) then
       expr("F"+k MOD 10+":=liste_rep_temp("+k+")");
     end;
  end;
end;

calcule_modules()
begin
  local k;
    for k from 1 to length(liste_fonctions) do
       if ISCHECK(k MOD 10) AND recalc_module(k) then
         liste_modules(k):=20*LOG(ABS(subst(liste_fonctions(k),'X','i*ALOG(X)')));
         recalc_module(k):=0; 
       end;
    end;
end;

calcule_phases()
BEGIN
local k,j,r,retard;
local f, a,num,denomi,cnum,cdenom,phi;
  for k from 1 to length(liste_fonctions) do
     if ISCHECK(k MOD 10) AND recalc_phase(k) then
       f:=replace(string(liste_fonctions(k)),"X","x");
       r:=instring(f,"e");
       if r then
                retard:=right(f,size(f)-1-r);
                f:=left(f,r-2);
       end;   
   
       a:=CAS.froot(EVAL(f),"x");
       num:=string(CAS.numer(EVAL(f)));
       denomi:=string(CAS.denom(EVAL(f)));
       cnum:=CAS.lcoeff(EVAL(num),"x");
       cdenom:=CAS.lcoeff(EVAL(denomi),"x");
       phi:=string(ARG(cnum/cdenom)); 
       FOR j FROM 1 TO length(a) STEP 2 DO
           IF RE(a(j))<>0 THEN 
                phi:=phi+"+"+a(j+1)+"*ATAN(("+IM(a(j))+"-X)/("+RE(a(j))+"))";
           ELSE IF a(j)==0 THEN
                    phi:=phi+"+"+a(j+1)+"*90";
                ELSE phi:=phi+"+"+a(j+1)+"*90*SIGN(X-"+IM(a(j))+")";
                END;   
           END; //fin IF
       END; //fin FOR j
     if r then phi:=phi+"+"+replace(retard,"x","X") end;
     phi:="'"+replace(phi,"X","ALOG(X)")+"'";
    liste_phases(k):=EXPR(phi);
    recalc_phase(k):=0;
   end; //fin if ischek
 end; //fin for k

END;

calcule_rep_temp()
begin
   local f, k;
     for k from 1 to length(liste_fonctions) do
        if ISCHECK(k MOD 10) AND recalc_temp(k) then
          f:=REPLACE(STRING(liste_fonctions(k)),"X","x");
          f:=f+"*1/x,x,x";
          f:="'("+REPLACE(STRING(CAS.ilaplace(EVAL(f))),"x","X")+")*PIECEWISE(X<0,0,X≥0,1)'";
          IF instring(f,"ilaplace") 
            THEN MSGBOX("Problème avec F"+k MOD 10); CONTINUE;
            ELSE liste_rep_temp(k):=EXPR(f);
          END;
          recalc_temp(k):=0;
        end;
     end;
end;


Symb()
begin
  modif:=1;
  replace_les_fonctions;
  STARTVIEW(0,1);
end;

Plot()
begin
  local choix;
  if modif then copie_les_fonctions end;
  CHOOSE(choix,"Choisissez un type de tracé",{"Module","phase","réponse indicielle"});
  CASE
   IF choix==1 THEN calcule_modules; place_les_modules;Ytick:=20 END;
   IF choix==2 THEN calcule_phases; place_les_phases;Ytick:=45 END;
   IF choix==3 THEN calcule_rep_temp; place_les_rep_temp; Xmin:=−0.2 END;
   //DEFAULT
  END;
  STARTVIEW(1,1);
end;

START()
begin
 modif:=1;
 replace_les_fonctions;
 STARTVIEW(0,1);
end;

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
04-23-2016, 11:10 AM (This post was last modified: 04-23-2016 11:26 AM by dg1969.)
Post: #5
RE: [1/2 SOLVED] New FW10077 problem-CAS command in program context
Thank you Tim for this support very efficient and incredibly fast !

My Bode plot App works now like a charm... If I find time I would add the Black and Nyquist plot by dialogue between several other custum applications based on parametric plot app...


But a problem remains: I can not compile the code if I choose coma in digital grouping (123 456,789) despite the pragma command... And if I first check with success the code (with 123 456.789 setting) and then change the option (123 456,789) after the release of the program editor, then the third choice plot (step response) fails...
Find all posts by this user
Quote this message in a reply
04-25-2016, 02:55 PM
Post: #6
RE: [1/2 SOLVED] New FW10077 problem-CAS command in program context
Will investigate...

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)