HP Forums

Full Version: Problem with equation in Programming
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys i have a problem with a program, i need solve a 3grade equation, i input the code but i dont have the solution
When i solve in home window i have the solution, why?

code:
Code:
EXPORT prueba1()
BEGIN
LOCAL d,ar,So,t,S;
LOCAL E,A,Tc;

A:=123;
d:=20;
t:=30;
S:=356;
E:=234;
ar:=98;
So:=342;

Tc:=CAS.solve("A=d*(15-t)*S*E-x+(((ar^2)*So^2)*S*E)/(24*x^2)","x");
MSGBOX(" solution" +(Tc));

END;

programming:
[attachment=2115]

home window:
[attachment=2116]
This seems to work:

Code:

EXPORT prueba1()
BEGIN
LOCAL d,ar,So,t,S;
LOCAL E,A,Tc;

A:=123;
d:=20;
t:=30;
S:=356;
E:=234;
ar:=98;
So:=342;

Tc:=solve("A=d*(15-t)*S*E-x+(((ar^2)*So^2)*S*E)/(24*x^2)","x");
MSGBOX(Tc);

END;
no, take me the same error Sad

"{}"
If you want "that" result, this take you there:

Code:

export AA:=123,d:=20,t:=30,SA:=356,EA:=234,ar:=98,So:=342;
EXPORT prueba1()
BEGIN
// LOCAL d,ar,So,t,S;
// LOCAL E,A,Tc;

// A:=123;
// d:=20;
// t:=30;
// S:=356;
// E:=234;
// ar:=98;
// So:=342;

// Tc:=solve("A1=d*(15-t)*S*E-x+(((ar^2)*So^2)*S*E)/(24*x^2)","x");

  return solve("AA=d*(15-t)*SA*EA-x+(ar^2*So*EA)/(24*x^2)","x");

END;
no, it is part of a bigger program, the variables are obtained and then solve the equation
I do not understand why other equations solved and that no

how i can use function fsolve?
There are two pertinent points:

1. The formula used in your program is not the same as the formula used to manually produce the values in your screenshot. The difference is in the paren's.

2. Local variables in HOME mode don't cross over to CAS mode as expected. That is why the snippet I sent (with GLOBAL variables) produces the same result as obtained in your screenshot; or, conversely, why your program isn't working as you expect.

There are ways to get around this, such as by not mixing HOME and CAS program constructs, use of global variables, and possibly other means. You can work out the details from this information.
This is closer to your original program, with output matching your screenshot:

Code:

export So:=342,ar:=98,d:=20,t:=30;   //  Globals persist in HOME and CAS modes
EXPORT prueba1()
BEGIN

  local Tc;    // Restricted to HOME mode
  restart;     // Clears conflicting CAS vars and settings 
  HDigits:=2;  // Added for display convenience

  A:=123;      //  Uses reserved variable
  E:=234;      //  Uses reserved variable
  S:=356;      //  Uses reserved variable

// LOCAL d,ar,So,t,S;
// LOCAL E,A,Tc;

// A:=123;  //  Don't mix local and reserved variables
// d:=20;   //  Don't mix local HOME and CAS variables
// t:=30;   //  Don't mix local HOME and CAS variables
// S:=356;  //  Don't mix local and reserved variables
// E:=234;  //  Don't mix local and reserved variables
// ar:=98;  //  Don't mix local HOME and CAS variables
// So:=342; //  Don't mix local HOME and CAS variables 
// Tc:=CAS.solve("A=d*(15-t)*S*E-x+(((ar^2)*So^2)*S*E)/(24*x^2)","x");  // List result doesn't match screenshot from post

  Tc:=solve("A=d*(15-t)*S*E-x+(ar^2*So*E)/(24*x^2)","x");  // List matches screenshot from post.            

  msgbox("Solution: " + string(Tc));  // Convert list to string object 

END;
Reference URL's