Post Reply 
= to ==, why? [SOLVED]
12-10-2016, 09:39 PM (This post was last modified: 12-10-2016 09:59 PM by Han.)
Post: #6
RE: = to ==, why?
In your third example, just comment out the export equ line (so that equ is created as a CAS variable) for a quick fix.

(12-10-2016 07:07 PM)compsystems Wrote:  The second version "deductionQuadFormula_2()" (works fine), to show intermediate steps, is required to convert it to string. An alternative code may exist

Why are you converting the CAS operations into strings? You can simply print the strings that show what steps you are doing, and then evaluate the actual operations using the actual CAS commands rather than using expr(...).

Code:
print("> factor(answer)");
equ:=factor(equ);
print("> " + equ);

Quote:The third version "deductionQuadFormula_3()", same as the previous one but using a subfunction to not repeat code (it does not work). An alternative code may exist, Who can code it?

Unless the images provide information that your code itself cannot generate, there is really no need to include them because it makes your post that much more difficult to read. Also, please don't edit your original post in that manner. Instead, insert "EDIT:" and add more to your post. Otherwise, when existing responses to your original text it may no longer make sense since you have changed your original post.

Anyway, here is an incomplete example (run as quad(0) or quad(1) for no pause or with pause).

PHP Code:
#cas
quad(p):=
BEGIN
  local eq
;

  print(
"Quadratic Formula");

  
dostep('assume(a>0)',p);
  
dostep('equ1:=a*x^2+b*x+c=0',p); 
  
dostep('equ1:=equ1*4*a',p);
  
dostep('equ1:=expand(equ1)',p);
  
dostep('equ1:=equ1+b^2-4*a*c',p);
  
dostep('equ1:=simplify(equ1)',p);
  
dostep('equ1:=factor(equ1)',p);
  
// more steps here
END;

dostep(cas,p):=
begin
  
print(cas);
  print(eval(
cas)); // or use print("> " + eval(cas))
  
if p then
    
print("                                                                [PAUSE]");
    
wait();
  else
    print(
"");
  
end
end;
#end 

Here's an alternative that prints something different from what is actually being computed.

PHP Code:
#cas
quad(p):=
BEGIN
  local eq
;

  print(
"Quadratic Formula");

  
dostep("assume(a>0)",'assume(a>0)',p);
  
dostep("equ1:=a*ax^2+b*x+c=0",'equ1:=a*x^2+b*x+c=0',p); 
  
dostep("answer * 4*a",'equ1:=equ1*4*a',p);
  
dostep("expand(answer)",'equ1:=expand(equ1)',p);
  
dostep("answer + b^2-4*a*c",'equ1:=equ1+b^2-4*a*c',p);
  
dostep("simpify(answer)",'equ1:=simplify(equ1)',p);
  
dostep("factor(answer)",'equ1:=factor(equ1)',p);
  
// more steps here
END;

dostep(s,cas,p):=
begin
  
print("> "+s);
  print(eval(
cas));
  if 
p then
    
print("                                                                [PAUSE]");
    
wait();
  else
    print(
"");
  
end
end;
#end 

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
= to ==, why? [SOLVED] - compsystems - 12-09-2016, 05:53 PM
RE: = to ==, why? - Han - 12-09-2016, 07:58 PM
RE: = to ==, why? - compsystems - 12-09-2016, 10:15 PM
RE: = to ==, why? - Han - 12-10-2016, 05:46 AM
RE: = to ==, why? - compsystems - 12-10-2016, 07:07 PM
RE: = to ==, why? - Han - 12-10-2016 09:39 PM
RE: = to ==, why? - compsystems - 12-11-2016, 03:08 PM



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