Post Reply 
Problem with equation in Programming
05-29-2015, 02:38 PM
Post: #1
Problem with equation in Programming
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:
   

home window:
   

:3
Visit this user's website Find all posts by this user
Quote this message in a reply
05-29-2015, 05:47 PM
Post: #2
RE: Problem with equation in Programming
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;
Find all posts by this user
Quote this message in a reply
05-29-2015, 05:54 PM
Post: #3
RE: Problem with equation in Programming
no, take me the same error Sad

"{}"

:3
Visit this user's website Find all posts by this user
Quote this message in a reply
05-29-2015, 06:40 PM
Post: #4
RE: Problem with equation in Programming
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;
Find all posts by this user
Quote this message in a reply
05-29-2015, 08:50 PM (This post was last modified: 05-29-2015 08:55 PM by nakjaen.)
Post: #5
RE: Problem with equation in Programming
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?

:3
Visit this user's website Find all posts by this user
Quote this message in a reply
05-29-2015, 10:29 PM
Post: #6
RE: Problem with equation in Programming
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.
Find all posts by this user
Quote this message in a reply
05-30-2015, 12:08 PM (This post was last modified: 05-30-2015 12:10 PM by DrD.)
Post: #7
RE: Problem with equation in Programming
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;
Find all posts by this user
Quote this message in a reply
Post Reply 




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