![]() |
|
![]() | ||
|
Subject:
math problems solution
Category: Computers Asked by: ted1923-ga List Price: $2.00 |
Posted:
15 Jun 2004 15:46 PDT
Expires: 15 Jul 2004 15:46 PDT Question ID: 361588 |
I am looking for BASIC computer language program to solve simultaneous equations of 5 or more unknowns | |
| |
| |
| |
| |
|
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: math problems solution
From: saem_aero-ga on 16 Jun 2004 11:38 PDT |
I would recommend a google search for the algorithm called "gaussian elimination". Here is a FORTRAN subroutine i wrote a long time ago which performs guassian elimination. Note you must set up your equation in the form Ax=B. If you want to be really efficient make one for LU decomp. I have a LU decomp algorithm but I can't find it. Anyway a quick translation to your basic language from FORTRAN should solve ur little problem =) !gauss elimination - This algorithm is verified but is not yet robust. !the diagonal elements must be non-zero.. subroutine gauss(A, U, Q, n) integer, intent(in) :: n !matrix size. real, intent(inout) :: A(1:n,1:n) !coefficient matrix. real, intent(inout) :: Q(1:n) !source term. real, intent(out) :: U(1:n) !return this solution to be returned by the subroutine. real :: multiply, summer integer :: baserow,i,j,k !temperar variables to see if this works: baserow = 0 !this assumes that element A(1,1) is NOT zero. if (A(1,1) == 0)then write(*,*) "ERROR on baserow forumlation A(1,1)==0" end if !this loop has been varified to change Q and A to proper matrix. do j=1,n-1!j is column baserow = j if(A(baserow,j)==0)then write(*,*) "ERROR, divide by zero on multiply formulation" end if !forumate the multiplyer. do i = j+1,n !is row multiply = A(i,j)/(A(baserow,j)) A(i,j) = 0 !explicitly known that this is zero. do k=j+1,n !go through elements (modify row) A(i,k)=A(i,k)-multiply*A(baserow,k) end do !modify the Q matrix. Q(i)=Q(i)-multiply*Q(baserow) end do end do !The upper triangle matrix should now be formed. !Need to have backward substitution in place next !It is now time to solve for U(i->n) by backward substitution. do i=n,1,-1 summer = 0 !reset our summation tool do k=i+1,n summer = summer - A(i,k)*U(i) end do U(i)=(Q(i)+summer)/A(i,i) end do end subroutine gauss |
Subject:
Re: math problems solution
From: ted1923-ga on 17 Jun 2004 06:05 PDT |
this is all very interesting ,i suppose , however it is all incomprehensible to me. my limited ken ,i guess. I am looking for something that looks more like the following,(although this program works on one computer the computer i would like to use has "variablE identification problem" with statements with the *) 1:print?simultaneous equations? 2:input?want new equations??,H$ 3ifH$=?Y?then12 4input?want changes to equations?,I$5 5:if I$=?Y? then 50 : DEFM 99 6: input?want to solve Equations??, J$ 7: if J$=?Y? then 30 8:input ?want to list equations?? ,L$ 9: if L$=?Y? then 40 10: input ?want anwers again?? ,Z$ 11: if Z$=?Y? then 38: end 12: input ?N=??,F 13: if >1 then 23 22: goto 12 23:for A=1 to F: Print?Row?;A 24:forB=1 to F:G=7+8*A+B 25: A(G)=0: input A(G) 26: next B :G=7+A : A(G)=0: input?=??,A(G) 28 : next A:goto 2 30: for A=1 to F-1: if A(7+9*A)=0 then 60 31: for B=A+1 to F 32: E= -A(7+8*B+A)/ A(7=9*A): A(7+8*B+A) 33 : G=7+8*B+D : A(G)=A(A)+E*A(7+8*A+D) : next D * 34 : A(7+B)= A(7+B)+E*A(7+A) : next B : next A 36 :for A=F-1 to step-1 : G=7+A : for B=A+1 to F 37 : A(G)=A(G)- A(7+B)*A(G+7*A+B) : next B :A(G)=A(G)/A(G+8*A) : next A * 38: Beep 2 : for A=1 to F: G=7+A : print ?X(?;A;?)= ? : ; A(G) : next A 39 : print ?done? : goto 2 40 : for A= 1 to F : for B=1 to F : G=7+8*A=B : print ? E(?;A;B;?)= ? ;A(G) * 41 : next B : G=7+A : print ?C(?;A;?)=? : ; A(G) 42 next A : goto 2 50: input ?element??,C: goto 54 51 : goto 2 54 : A= int(C/10): B= C-10*A : if A<1 then 50 : if A>F then 50 55 : if B<0 then 50: if B>f then 50: G=7+8*A+B : if B=0 let G=7+A * 56 : print ?E(?;A;B;?)=?;A(G) 57 ? input ?new value??, A(G) 58 goto 50 60 : for B = A+1 to F :if A(7+8*B+A)=0 next B : beep 61 : print ?unsolvable? : goto 2: forC=1 to F : G=A(7+A+C) 62 : A(7+8*A+C)=A(7=8*B+C) : A(7+8*B+C)=G : next C 64 : G=A(7+A) = A(7+B):A(7+B)=G : goto 31: for C=1 to F |
Subject:
Re: math problems solution
From: pne-ga on 17 Jun 2004 10:16 PDT |
Compare http://answers.google.com/answers/threadview?id=361846 |
Subject:
Re: math problems solution
From: saem_aero-ga on 17 Jun 2004 10:23 PDT |
I'm curious, what basic program are you using to execute this code? I was looking at lines such as the ones you marked with *, it looks to me like you are trying to reference the variable 'A' in a improper way. Sometimes the program wishes to look at the variable as an array (like x(1), x(2), x(3)) or sometimes it wishes to not look at it as an array (x, y, z). The lines you have * all have something in common. They all have A with and without the (). A() is a array and A without the () is a scalar. Its confusing when you mix the two in your program. What you might want to try, to get around this little problem is... to change: All A to Q (because Q is not used yet) All A(....) Leave this alone All A(...A...) if you find a A inside of A() then change the A to Q. That might get around your variable identification problem. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |