Jalkhov
Member in Training
██████████████████▓░ 99%
Posts: 41
|
Post by Jalkhov on Feb 17, 2021 0:01:09 GMT
I need help with a BASIC code, can help me with that in this forum? In case of no, exist a forum about BASIC? Thanks (Sorry for my english, i am latin).
|
|
|
Post by tsh73 on Feb 17, 2021 7:11:24 GMT
Sure you can ask, and we will try to answer. The problem is that our answers may not fit to your version of BASIC. This is Just BASIC forum, and Just BASIC is Windows-only thing. What BASIC, what OS you use?
|
|
Jalkhov
Member in Training
██████████████████▓░ 99%
Posts: 41
|
Post by Jalkhov on Feb 17, 2021 11:08:33 GMT
Sure you can ask, and we will try to answer. The problem is that our answers may not fit to your version of BASIC. This is Just BASIC forum, and Just BASIC is Windows-only thing. What BASIC, what OS you use? The truth is that I don't know which version I have, I am not a BASIC expert, so I started to use it with Vintage BASIC, I tried to find the interpreter that best adapted to the syntax of the old computers. It is important to clarify that my Operating System is Windows. My urgency to learn this language is that I have a code that I need to translate to another language, or at least to know what each line does and to be able to translate it to Python which is my target language. Here I leave the code: 5 STOP :CLEAR :WAIT 5: INPUT "# DE TRAMOS="; N : Z = N +1
10 DIM W(N),P(N),L(N),A(N),B(N),K(N),R(Z+1),C(Z+1,Z+1)
20 INPUT "TIENE VOLADOS";H$ : IF H$="SI" THEN INPUT "#DEVLS."; V : ELSE 70
25 FOR I=1 TO V
30 PRINT "WV(";I;")=";:INPUT W(I):PRINT "LV(";I;")=";:INPUT L(I)
35 PRINT "AY(";I;")=";:INPUT A(I):PRINT "PV(";I;")=";:INPUT P(I)
40 M=W(I)*L(I)^2/2+P(I)*A(I)
50 IF I=1 THEN C(I,I-1)=M: ELSE 65
60 C(Z,Z+1)=-M
65 NEXT I
70 FOR I=1 TO N:PRINT "W";I;"=";:INPUT W(I):PRINT "P";I;"=";:INPUT P(I)
80 PRINT "L" ; I ; "=" ; : INPUT L(I):PRINT "A";I;"=";:INPUT A(I)
90 PRINT "B" ; I ; "=" ; : INPUT B(I):PRINT "I";I;"=";:INPUT K(I)
100 R(I)=4*K(I)/L(I)
110 NEXT I
120 FOR I=1 TO N
130 C(I,I+1)=(W(I) * L(I) ^ 2 / 12 + P(I) * A(I) * B(I) ^ 2 / L(I) ^ 2) * -1
140 C(I+1,1)= W(I) * L(I) ^ 2 / 12 + P(I) * B(I) * A(I) ^ 2 / L(I) ^ 2
150 NEXT I
160 FOR P=1 TO 10:FOR I=1 TO N+1
170 M1=(C(I,I-1)+C(I,I+1))*(-R(I-1)/(R(I-1)+R(I)))
180 M2=(C(I,I-1)+C(I,I+1))*(-R(I)/(R(I-1)+R(I)))
190 M3=M1*.5
200 M4=M2*.5
210 C(I,I+1)=C(I,I+1)+M2:C(I,I-1)=C(I,I-1)+M1
220 C(I-1,I)=C(I-1,I)+M3:C(I+1,I)=C(I+1,I)+M4
230 NEXT I: NEXT P
280 FOR I=1 TO N+1
290 PRINT "M";I;">";I-1;"=";ROUND(C(I,I-1),-3)
300 PRINT "M";I;">";I-1;"=";ROUND(C(I,I+1),-3)
310 NEXT I
320 FOR I = 1 TO N:PRINT "TRAMP";I
330 K = W(I)*L(I)/2:K1=(C(I,I+1)+C(I+1,1))/L(I)
340 B1 = K-K1+P(I)*B(I)/L(I):V2=-(K+K1+P(I)*A(I)/L(I))
350 IF SGN(V1) = SGN(V2) THEN 360:ELSE 370
360 PRINT "V";I;">D=";ROUND(V1,-3),"V";I+1;">I=";ROUND(V2,-3):PRINT "NO M+"
365 GOTO 460
370 X = V1*L(I)/(V1 + ABS(V2)):IF X > A(I) THEN 380: ELSE P(I)=0
380 M = V1*X-W(I)*X^2/2-P(I)*(X-A(I))+C(I,I+1):IF M < 0 THEN 360
390 C1=(-X)^2:C2=-X:C3=(L(I)-X)^2:C4=(L(I)-X):K1=C(I,I+1)-M:C=M
400 K2 = -C(I+1,I)-M:D=C1*C4-C2*C3:A=(K1*C4-K2*C2)/D:B=(K2*C1-K1*C3)/D
410 Q=(B^2-4*A*C)^.5:X2=(-B+Q)/2/A:X3=(-B-Q)/2/A
420 IF X2 < X3 THEN X4 = X + X2:X5=L(I)-(X*X3): GOTO 440
430 X4=X+X3:X5=L(I)-(X+X2
440 PRINT "V";I;">D=";ROUND(V1,-3),"V";I+1;">I=";ROUND(V2,-3),"M+";ROUND(M,-3)
450 PRINT "X>";I;"=";ROUND(X4,-3),"X>";I+1;"=";ROUND(X5,-3),"X>M+";ROUND(X,-3)
460 NEXT I However, when running this code as it is in Vintage BASIC I get errors in certain places, for example in the wait, I imagine that Vintage does not emulate the original language, a person taught me that code in a programmable calculator and it ran excellently, so I guess that it is another version of BASIC different from the computer and Vintage. Anyway, I had to document myself on the internet to learn some BASIC and try to translate it, but wow, it's difficult, I'm stuck on some things, especially the multi-dimensional arrays. I have seen that there are some BASIC to C converters around, like BaCon, but I don't have access to a Linux OS, and the alternative for Windows sucks (BCX). If someone could translate it for me I would appreciate it very much, it is for my university project, clearly I would give all the corresponding credits, for example to the forum and to the person who helped me, thank you very much in advance.
|
|
|
Post by tsh73 on Feb 17, 2021 12:14:36 GMT
All I could do is to make it work in Just BASIC (I pretty sure first three statements in a program are bogus ones) (and I pass it through REMLINE.BAS so only labels left are used by GOTO) Do you know what it supposed to do? Do you have right numbers to enter (or better yet, transcript or program working - what goes in what goes out)?
As of now it works and does something. But I have no idea what.
EDIT as for multi-dimensioned arrays, arrays in BASIC is allocated with DIM statement So there is only one 2d array: C(,) And it looks from this program, that in this version of BASIC DIM ARR(N) arrays are allocated from 0 to N (I see index in FOR loop start from 1 and used as I-1) I believe C(i,j) will translate to python as
C[i][j] and lists in python are numbered from 0 too - but how lists are allocated in Python you better ask on Python forum.
'STOP :CLEAR :WAIT 5: INPUT "# DE TRAMOS="; N : Z = N +1 DIM W(N),P(N),L(N),A(N),B(N),K(N),R(Z+1),C(Z+1,Z+1) INPUT "TIENE VOLADOS";H$ : IF H$="SI" THEN INPUT "#DEVLS."; V : ELSE 70 FOR I=1 TO V PRINT "WV(";I;")=";:INPUT W(I):PRINT "LV(";I;")=";:INPUT L(I) PRINT "AY(";I;")=";:INPUT A(I):PRINT "PV(";I;")=";:INPUT P(I) M=W(I)*L(I)^2/2+P(I)*A(I) IF I=1 THEN C(I,I-1)=M: ELSE 65 C(Z,Z+1)=0-M 65 NEXT I 70 FOR I=1 TO N:PRINT "W";I;"=";:INPUT W(I):PRINT "P";I;"=";:INPUT P(I) PRINT "L" ; I ; "=" ; : INPUT L(I):PRINT "A";I;"=";:INPUT A(I) PRINT "B" ; I ; "=" ; : INPUT B(I):PRINT "I";I;"=";:INPUT K(I) R(I)=4*K(I)/L(I) NEXT I FOR I=1 TO N C(I,I+1)=(W(I) * L(I) ^ 2 / 12 + P(I) * A(I) * B(I) ^ 2 / L(I) ^ 2) * -1 C(I+1,1)= W(I) * L(I) ^ 2 / 12 + P(I) * B(I) * A(I) ^ 2 / L(I) ^ 2 NEXT I FOR P=1 TO 10:FOR I=1 TO N+1 M1=(C(I,I-1)+C(I,I+1))*(-R(I-1)/(R(I-1)+R(I))) M2=(C(I,I-1)+C(I,I+1))*(-R(I)/(R(I-1)+R(I))) M3=M1*.5 M4=M2*.5 C(I,I+1)=C(I,I+1)+M2:C(I,I-1)=C(I,I-1)+M1 C(I-1,I)=C(I-1,I)+M3:C(I+1,I)=C(I+1,I)+M4 NEXT I: NEXT P FOR I=1 TO N+1 PRINT "M";I;">";I-1;"=";ROUND(C(I,I-1),-3) PRINT "M";I;">";I-1;"=";ROUND(C(I,I+1),-3) NEXT I FOR I = 1 TO N:PRINT "TRAMP";I K = W(I)*L(I)/2:K1=(C(I,I+1)+C(I+1,1))/L(I) B1 = K-K1+P(I)*B(I)/L(I):V2=0-(K+K1+P(I)*A(I)/L(I)) IF SGN(V1) = SGN(V2) THEN 360:ELSE 370 360 PRINT "V";I;">D=";ROUND(V1,-3),"V";I+1;">I=";ROUND(V2,-3):PRINT "NO M+" GOTO 460 370 X = V1*L(I)/(V1 + ABS(V2)):IF X > A(I) THEN 380: ELSE P(I)=0 380 M = V1*X-W(I)*X^2/2-P(I)*(X-A(I))+C(I,I+1):IF M < 0 THEN 360 C1=(0-X)^2:C2=0-X:C3=(L(I)-X)^2:C4=(L(I)-X):K1=C(I,I+1)-M:C=M K2 = 0-C(I+1,I)-M:D=C1*C4-C2*C3:A=(K1*C4-K2*C2)/D:B=(K2*C1-K1*C3)/D Q=(B^2-4*A*C)^.5:X2=(0-B+Q)/2/A:X3=(0-B-Q)/2/A IF X2 < X3 THEN X4 = X + X2:X5=L(I)-(X*X3): GOTO 440 X4=X+X3:X5=L(I)-(X+X2) 'was missing last ) 440 PRINT "V";I;">D=";ROUND(V1,-3),"V";I+1;">I=";ROUND(V2,-3),"M+";ROUND(M,-3) PRINT "X>";I;"=";ROUND(X4,-3),"X>";I+1;"=";ROUND(X5,-3),"X>M+";ROUND(X,-3) 460 NEXT I
end
'-------------------------------- 'functions missing in JB function ROUND(x, n) 'n=3 -> 12345.678? ROUND=int(x*10^n)/10^n end function
function SGN(x) SGN = (x>0)-(x<0) end function
|
|
Jalkhov
Member in Training
██████████████████▓░ 99%
Posts: 41
|
Post by Jalkhov on Feb 17, 2021 13:11:57 GMT
It is to calculate a continuous beam of N sections (civil construction subject). I know that it is difficult to make a direct translation to another language, but it would be useful to me at least to know what is done in each line, because translated to Just Basic I am a bit confused because I don't know the language, but still thanks, I will have to continue investigating.
|
|
|
Post by honky on Feb 17, 2021 13:22:49 GMT
It should be said of what must make your program.
|
|
|
Post by tsh73 on Feb 17, 2021 13:33:10 GMT
Do you know Python? I pretty sure you can decipher INPUT (asking a number from user), PRINT (printing stuff out) IF THEN ELSE conditional statement, FOR loop (NEXT marks end of loop)
BASIC is just ordinary imperative language You have old variety without structural elements - so it uses GOTO instead of
IF condition THEN many lines of code ELSE many lines of code ENDIF
and
FOR I=... loop ... IF some condition CONTINUE (to next value of I) ... NEXT
There is no user functions here (except of functions SGN and ROUND I added) , so all k(i) etc things with brackets are array indexes
L(I) ^ 2 in BASIC means "L(I) squared"
Q=(B^2-4*A*C)^.5 is square root of (B^2-4*A*C) - looks like quadratic equation formula for me
I think everything else is math and assignments. Go ahead and ask if you find something not-so-clear.
Here I added indents to show for/next loops (ordinary loops with known number of repeats)
'STOP :CLEAR :WAIT 5: INPUT "# DE TRAMOS="; N : Z = N +1 DIM W(N),P(N),L(N),A(N),B(N),K(N),R(Z+1),C(Z+1,Z+1) INPUT "TIENE VOLADOS";H$ : IF H$="SI" THEN INPUT "#DEVLS."; V : ELSE 70 FOR I=1 TO V PRINT "WV(";I;")=";:INPUT W(I):PRINT "LV(";I;")=";:INPUT L(I) PRINT "AY(";I;")=";:INPUT A(I):PRINT "PV(";I;")=";:INPUT P(I) M=W(I)*L(I)^2/2+P(I)*A(I) IF I=1 THEN C(I,I-1)=M: ELSE 65 C(Z,Z+1)=0-M 65 NEXT I 70 FOR I=1 TO N:PRINT "W";I;"=";:INPUT W(I):PRINT "P";I;"=";:INPUT P(I) PRINT "L" ; I ; "=" ; : INPUT L(I):PRINT "A";I;"=";:INPUT A(I) PRINT "B" ; I ; "=" ; : INPUT B(I):PRINT "I";I;"=";:INPUT K(I) R(I)=4*K(I)/L(I) NEXT I FOR I=1 TO N C(I,I+1)=(W(I) * L(I) ^ 2 / 12 + P(I) * A(I) * B(I) ^ 2 / L(I) ^ 2) * -1 C(I+1,1)= W(I) * L(I) ^ 2 / 12 + P(I) * B(I) * A(I) ^ 2 / L(I) ^ 2 NEXT I FOR P=1 TO 10 FOR I=1 TO N+1 M1=(C(I,I-1)+C(I,I+1))*(-R(I-1)/(R(I-1)+R(I))) M2=(C(I,I-1)+C(I,I+1))*(-R(I)/(R(I-1)+R(I))) M3=M1*.5 M4=M2*.5 C(I,I+1)=C(I,I+1)+M2:C(I,I-1)=C(I,I-1)+M1 C(I-1,I)=C(I-1,I)+M3:C(I+1,I)=C(I+1,I)+M4 NEXT I NEXT P FOR I=1 TO N+1 PRINT "M";I;">";I-1;"=";ROUND(C(I,I-1),-3) PRINT "M";I;">";I-1;"=";ROUND(C(I,I+1),-3) NEXT I FOR I = 1 TO N:PRINT "TRAMP";I K = W(I)*L(I)/2:K1=(C(I,I+1)+C(I+1,1))/L(I) B1 = K-K1+P(I)*B(I)/L(I):V2=0-(K+K1+P(I)*A(I)/L(I)) IF SGN(V1) = SGN(V2) THEN 360:ELSE 370 360 PRINT "V";I;">D=";ROUND(V1,-3),"V";I+1;">I=";ROUND(V2,-3):PRINT "NO M+" GOTO 460 370 X = V1*L(I)/(V1 + ABS(V2)):IF X > A(I) THEN 380: ELSE P(I)=0 380 M = V1*X-W(I)*X^2/2-P(I)*(X-A(I))+C(I,I+1):IF M < 0 THEN 360 C1=(0-X)^2:C2=0-X:C3=(L(I)-X)^2:C4=(L(I)-X):K1=C(I,I+1)-M:C=M K2 = 0-C(I+1,I)-M:D=C1*C4-C2*C3:A=(K1*C4-K2*C2)/D:B=(K2*C1-K1*C3)/D Q=(B^2-4*A*C)^.5:X2=(0-B+Q)/2/A:X3=(0-B-Q)/2/A IF X2 < X3 THEN X4 = X + X2:X5=L(I)-(X*X3): GOTO 440 X4=X+X3:X5=L(I)-(X+X2) 'was missing last ) 440 PRINT "V";I;">D=";ROUND(V1,-3),"V";I+1;">I=";ROUND(V2,-3),"M+";ROUND(M,-3) PRINT "X>";I;"=";ROUND(X4,-3),"X>";I+1;"=";ROUND(X5,-3),"X>M+";ROUND(X,-3) 460 NEXT I
end 'functions missing in JB function ROUND(x, n) 'n=3 -> 12345.678? ROUND=int(x*10^n)/10^n end function
function SGN(x) SGN = (x>0)-(x<0) end function
|
|
Jalkhov
Member in Training
██████████████████▓░ 99%
Posts: 41
|
Post by Jalkhov on Feb 17, 2021 14:40:07 GMT
Thank you very much for the support, I will post my doubts separately: 1. NORMAL ARRAYS:This part: FOR I=1 TO N R(I)=4*K(I)/L(I) What it does is to insert elements in the array recursively No? Based on the value "I", that is, if I is 1, the result of "4*K(I)/L(I)" will be stored in position 1, right? I think I'm clear on that In python it would be something like this: array = []
for x in range(5): # iterate from 0 to 4 array.append(x)
print(array) In python you don't need to specify the index to append elements (not always), in this case append adds the elements one after the other, the output would be this: [0, 1, 2, 3, 4]
So if we do the following in BASIC: FOR I=0 TO 5 R(I)=I
The output would be similar to the Python output, right? 2. MULTI-DIMENSIONAL ARRAYSIn Python a multi-dimensional array would look like declared: multidarray=[[[1,2,3] , [4,5,6] , [7,8,9]]]
The contents of each element can be obtained: print(multidarray[0])
[1, 2, 3] # output
Or print(multidarray[0][1])
2 #output This line: C(I,I+1) = C(I,I+1)+M2:C(I,I-1) = C(I,I-1)+M1
I understand that: The result of C(I,I+1)+M2:C(I,I-1) will be inserted in the index depending on the value of IAnd the result of C(I,I-1)+M1 will be inserted in the index depending on the value of I + 1Above array C is stated as follows: C(Z+1,Z+1)
Suppose Z is 2: Then: C(2+1,2+1)
Would it result in an empty 3x3 array? 3. NEXTCould NEXT be taken as the end of the for cycle? That is, everything inside FOR and NEXT will be iterated inside the FOR? More than doubts, I want to know if I am making the right interpretations.
|
|
|
Post by tsh73 on Feb 17, 2021 19:09:41 GMT
Oh man... I *heard* that Python is different - but that is is *so* different I cannot grasp. From now on I will be scaring my fellow progammers with it ;)
But as they said "what one man build other could break" - that one devised other could understand.
Let's go. Python is foreign language for me, but Google is with us.
0. This is JustBASIC forum, JustBASIC I made it run. JustBASIC has his own peculiarities. One of them is that keywords are case-UN-sensitive, while variables are case-sensitive. So x and X is two different things (and x() is third thing, and it could be either array or function) dim and Dim and DIM are the same statement
00. BASIC tradition. You can use arrays without explicit DIM. That way, they will be allocated [0..10] on first occurence - and you get error if try to use with index >10
000.
FOR i=0 to 3 print i next i
produces FOUR values, last one included
1. NORMAL ARRAYS: arrays in BASIC are preallocated Then you run through
DIM R(5) it gets values 0 from R(0) to R(5) You can use R(0) or start from R(1) - it will be allocated anyway last item, R(5) allocated too You can use it (read it, use in computations) or write to it But once you went out of [0..5] range it will error
dim R(5) R(6)=1
Same goes to
R(6)=-1
They are "static" arrays - in the sense that you cannot add an item or extend the item
So from my view,
n=5 dim R(n) is like you do (Googled Python)
and then cut off add/expand/insert from R with a cable cutter. So it always be R[0] to R[n].
2. MULTI-DIMENSIONAL ARRAYS DIM C(n,n) Again, pre-allocated, filled with 0, indices from 0 to n. Something along
again without add/expand/insert And without ability to get single row or column. Only single cell with two indices, C(i,j)
(so in arrays) So all assignments in arrays in Basic NOT INSERT A THING in array - they CHANGE pre-allocated cell that is already there (allocated by DIM) So arrays are DIM-med so that indices never went over last item (or under 0) Or it will error and stop.
3. NEXT Yes it is marker for end of loop
exactly.
|
|
Jalkhov
Member in Training
██████████████████▓░ 99%
Posts: 41
|
Post by Jalkhov on Feb 17, 2021 20:31:18 GMT
First of all thank you very much for the support, I have already translated most of the code, now I have some doubts about the ROUND and SGN functions, I am trying to test the ROUND function in BASIC but I get 0, no matter what number I put, so I don't know if I am doing something wrong, because I translated it to python and it looks like this:
def ROUND(x, n): print((pow(x*10, n)) / pow(10,n)) pow is to raise the number of the first parameter to the power given in the second parameter, in Python it gives me numbers with decimals.
And I really have no idea what SGN is for.
Another thing, exist an error in the code, in line
B1 = K-K1+P(I)*B(I)/L(I):V2=0-(K+K1+P(I)*A(I)/L(I)) is
V1 = K-K1+P(I)*B(I)/L(I):V2=0-(K+K1+P(I)*A(I)/L(I) My mistake.
I have another small confusion, below the above mentioned line
GOTO 460
That line is not subject to any condition, that is, it will always be executed and the code that follows it will never be shown, right?
|
|
|
Post by tsh73 on Feb 17, 2021 21:38:02 GMT
1. It looks like Python has its own round() function and it works exactly as function I wrote - just use that (JB has no such function, Visual Basic seemingly has)
2. SGN is sign fumction is a function that shows number sign By definition it is 1 for x>0, 0 for x=0, -1 for x<0 I googled why Python doesn't have it - and it looks like it's too easy to implement - but too hard to implement right (how to work with NaNs and complex numbers, for example)
It is used once here
if SGN(V1) = SGN(V2) and it is true if both V1 and V2 positive, or both negative. Old hack vould be
if V1*V2>0
As for error with closing ")" - I pretty sure program will not compile if brackets do not match. Be it Python or BASIC. Just BASIC did not compile unitl I added ")" at line 430.
About GOTO 460
this line
IF SGN(V1) = SGN(V2) THEN 360:ELSE 370 goes to 360 or 370, depending on condition. And 370 is just that "the code that follows" GOTO 460, so you go there on ELSE.
|
|
Jalkhov
Member in Training
██████████████████▓░ 99%
Posts: 41
|
Post by Jalkhov on Feb 17, 2021 22:45:44 GMT
NEWS!
I just got the input data from the code and the data I should have output, this should help more to develop the code right?
INPUT VALUES:
NUMERO DE TRAMOS = 2 TIENE VOLADOS = NO NUMERO DE VOLADOS = (NOT IN THIS EXAMPLE) W1 = 2 P1 = 2 L1 = 4 A1 = 2 B1 = 2 I1 = 1 W2 = 2 P2 = 2 L2 = 4 A2 = 2 B2 = 2 I2 = 1
OUTPUT VALUES: M1>0=0 M1>2=0 M2>1=5,50 M2>3=-5,50 M3>2=0 M3>4=0 TRAMP1 V1>D=3,62 V2>I=6,38 NO M+
M+ 3,15
X>1=0
X>2=0,99
X>M+=1.45 TRAMP2 V2>D=6.38 V3>I=3.62
NO M+ M+=3,15
X>2=0,99
X>3=0
X>M+=2.55
First let's focus on getting the output right, and again, thank you very much for the help. (The strikethroughs are placed like this because they do not appear in the output of the code as it currently stands.)
Ok, I have serious problems with this code segment, those GOTO jumps confuse me too much, since python takes identation very seriously, those IF with GOTO have me in trouble. FOR I = 1 TO N:PRINT "TRAMP";I K = W(I)*L(I)/2:K1=(C(I,I+1)+C(I+1,1))/L(I) V1 = K-K1+P(I)*B(I)/L(I):V2=0-(K+K1+P(I)*A(I)/L(I)) IF SGN(V1) = SGN(V2) THEN 360:ELSE 370 360 PRINT "V";I;">D=";ROUND(V1,-3),"V";I+1;">I=";ROUND(V2,-3):PRINT "NO M+" GOTO 460 370 X = V1*L(I)/(V1 + ABS(V2)):IF X > A(I) THEN 380: ELSE P(I)=0 380 M = V1*X-W(I)*X^2/2-P(I)*(X-A(I))+C(I,I+1):IF M < 0 THEN 360 C1=(0-X)^2:C2=0-X:C3=(L(I)-X)^2:C4=(L(I)-X):K1=C(I,I+1)-M:C=M K2 = 0-C(I+1,I)-M:D=C1*C4-C2*C3:A=(K1*C4-K2*C2)/D:B=(K2*C1-K1*C3)/D Q=(B^2-4*A*C)^.5:X2=(0-B+Q)/2/A:X3=(0-B-Q)/2/A IF X2 < X3 THEN X4 = X + X2:X5=L(I)-(X*X3): GOTO 440 X4=X+X3:X5=L(I)-(X+X2) 'was missing last ) 440 PRINT "V";I;">D=";ROUND(V1,-3),"V";I+1;">I=";ROUND(V2,-3),"M+";ROUND(M,-3) PRINT "X>";I;"=";ROUND(X4,-3),"X>";I+1;"=";ROUND(X5,-3),"X>M+";ROUND(X,-3)
460 NEXT I
EDIT
Ok, I've written the code in BASIC as if it were Python, trying to avoid the GOTO and so on, I want to know if this is a good solution. FOR I = 1 TO N:PRINT "TRAMP";I K = W(I)*L(I)/2:K1=(C(I,I+1)+C(I+1,1))/L(I) V1 = K-K1+P(I)*B(I)/L(I):V2=0-(K+K1+P(I)*A(I)/L(I)) IF SGN(V1) = SGN(V2) THEN 360 PRINT "V";I;">D=";ROUND(V1,-3) "V";I+1;">I=";ROUND(V2,-3) PRINT "NO M+" ELSE 370 X = V1*L(I)/(V1 + ABS(V2)) IF X > A(I) THEN GOTO 380 ELSE P(I)=0
GOTO 460
370 X = V1*L(I)/(V1 + ABS(V2)):IF X > A(I) THEN 380: ELSE P(I)=0
380 M = V1*X-W(I)*X^2/2-P(I)*(X-A(I))+C(I,I+1) IF M < 0 THEN 360 PRINT "V";I;">D=";ROUND(V1,-3) "V";I+1;">I=";ROUND(V2,-3) PRINT "NO M+"
C1=(0-X)^2:C2=0-X:C3=(L(I)-X)^2:C4=(L(I)-X):K1=C(I,I+1)-M:C=M K2 = 0-C(I+1,I)-M:D=C1*C4-C2*C3:A=(K1*C4-K2*C2)/D:B=(K2*C1-K1*C3)/D Q=(B^2-4*A*C)^.5:X2=(0-B+Q)/2/A:X3=(0-B-Q)/2/A
IF X2 < X3 THEN X4 = X + X2:X5=L(I)-(X*X3) X4=X+X3:X5=L(I)-(X+X2) ELSE: 440 PRINT "V";I;">D=";ROUND(V1,-3),"V";I+1;">I=";ROUND(V2,-3),"M+";ROUND(M,-3)
PRINT "X>";I;"=";ROUND(X4,-3),"X>";I+1;"=";ROUND(X5,-3),"X>M+";ROUND(X,-3)
460 NEXT I But the GOTO 460 keeps bothering me
|
|
|
Post by tsh73 on Feb 18, 2021 3:10:40 GMT
|
|
|
Post by tsh73 on Feb 18, 2021 11:22:34 GMT
I think I found one more error in code - minor one, in labeling output it's (+) in
"M";I;">";I+1; at
FOR I=1 TO N+1 PRINT "M";I;">";I-1;"=";ROUND(C(I,I-1),-3) PRINT "M";I;">";I+1;"=";ROUND(C(I,I+1),-3) NEXT I
But for me it produces really bug numbers My guess that
FOR P=1 TO 10 FOR I=1 TO N+1 M1=(C(I,I-1)+C(I,I+1))*(-R(I-1)/(R(I-1)+R(I))) M2=(C(I,I-1)+C(I,I+1))*(-R(I)/(R(I-1)+R(I))) M3=M1*.5 M4=M2*.5 C(I,I+1)=C(I,I+1)+M2:C(I,I-1)=C(I,I-1)+M1 C(I-1,I)=C(I-1,I)+M3:C(I+1,I)=C(I+1,I)+M4 NEXT I NEXT P is some numerical method, that re-calculates C array. And it should converge. But as for now, it is not. There really should be some errors in these lines.
( I added some printing with
gosub [prtC]
[prtC] print "==================================" 'C(Z+1,Z+1) for i1 = 0 to Z+1 for j1=0 to Z+1 print C(i1,j1), next print next return
and I see numbers get bigger and bigger.)
Could you explain meaning of inputs - forces, moments, lengths, weights, whatever? May be picture explaining sample data? (I wonder if there are some online calculator doing the same, so we could check outputs)
|
|
Jalkhov
Member in Training
██████████████████▓░ 99%
Posts: 41
|
Post by Jalkhov on Feb 18, 2021 12:27:40 GMT
Ok, let's take it one step at a time: 1. LABELING ERRORDo you mean it should look like this? "M+";I;">";I+1;
2. MEANING OF INPUTS: FORCES, MOMENTS, LENGTHS, WEIGHTS...
Not really, I don't have much knowledge of the meaning of these variables 3. MAY BE PICTURE EXPLAINING SAMPLE DATA?The only thing I have is the program as it was given to me, on a sheet, the results it should give with the given parameters. 4. I WONDER IF THERE ARE SOME ONLINE CALCULATOR DOING THE SAME, SO WE COULD CHECK OUTPUTS
This is the calculator used by the engineer who gave me the code to run the system, I was looking on the internet and there is no exact emulator for that model.
CASIO_FX-850P
EXTRA
So you say there are errors here?
FOR P=1 TO 10 FOR I=1 TO N+1 M1=(C(I,I-1)+C(I,I+1))*(-R(I-1)/(R(I-1)+R(I))) M2=(C(I,I-1)+C(I,I+1))*(-R(I)/(R(I-1)+R(I))) M3=M1*.5 M4=M2*.5 C(I,I+1)=C(I,I+1)+M2:C(I,I-1)=C(I,I-1)+M1 C(I-1,I)=C(I-1,I)+M3:C(I+1,I)=C(I+1,I)+M4 NEXT I NEXT P
|
|