Page 1 of 2

Barycentre

Unread postPosted: 15 Feb 2014, 12:30
by marcoz
I would like to do this program but I am stuck on a few things ... Can anyone help me? Items can be three, four, five, etc ...

baricent()
Prgm
InputStr "How many elements ?",str1
If str1="" Then
.............................. Place a cycle for to say: If the items are five then enter this data .....

InputStr "Enter A1",str2
InputStr "Enter A2",str3
InputStr "Enter A3",str4
InputStr "Enter A4",str5
InputStr "Enter A5",str6
InputStr "Enter D1",str7
InputStr "Enter D2",str8
InputStr "Enter D3",str9
InputStr "Enter D4",str10
InputStr "Enter D5",str11


Pause "M1=A1*D1"
Pause str2*str7
.....................

Mtot= .......

xG=....
yG=....
zG=...

Re: Barycentre

Unread postPosted: 15 Feb 2014, 12:37
by pierrotdu18
You have to do a for loop :

Code: Select all
baricent()
Prgm

A:={}  -- The list which is gonna contain the A elements
D:={}  -- The list which is gonna contain the D elements

InputStr "How many elements ?",str1

For k,1,str1
InputStr "Enter A"&string(k),str2
A:=augment(A,{str2})
EndFor

For k,1,str1
InputStr "Enter D"&string(k),str2
D:=augment(D,{str2})
EndFor

EndPgrm



Then, I didn't really understand what you wanted to do ;)

Re: Barycentre

Unread postPosted: 15 Feb 2014, 12:40
by marcoz
I want to calculate the center of gravity of a structure in three dimensions...
Now I try and I'll know

Re: Barycentre

Unread postPosted: 15 Feb 2014, 12:45
by pierrotdu18
A structure un three dimensions? Defined by what? Your A points and your D points?...

Re: Barycentre

Unread postPosted: 15 Feb 2014, 12:55
by marcoz
A represents the length / surface
D represents the density

A and D are data of the problem


I want to insert A and D according to the number of elements that have the structure (may be two, three or four, etc. ...)

I want him to calculate the mass of each element, knowing that the mass is given by M = D / A


Then I want to calculate the total mass .... What is given by M1 + M2 + M3 ......


and after this calculation the center of gravity

Re: Barycentre

Unread postPosted: 15 Feb 2014, 13:02
by pierrotdu18
EDIT : It is not InputStr but Input, you must enter numbers, don't you?

Code: Select all
baricent()
Prgm

A:={}  -- The list which is gonna contain the A elements
D:={}  -- The list which is gonna contain the D elements
M:={} -- The list which is gonna contain the M elements
result:=0 -- The result

InputStr "How many elements ?",str1

For k,1,str1
Input "Enter A"&string(k),str2
A:=augment(A,{str2})
EndFor

For k,1,str1
Input "Enter D"&string(k),str2
D:=augment(D,{str2})
EndFor

For k,1,str1
temp:=D[k]*A[k]
M:=augment(M,{temp})
EndFor

For k,1,dim(M)
result:=result+M[k]
EndFor

Disp result -- The sum of the Mk elements

EndPgrm

Re: Barycentre

Unread postPosted: 15 Feb 2014, 13:05
by marcoz
The center of gravity

Xg=[somm(xg^i* M^i) ] / M(total)
Yg=[somm(yg^i* M^i) ] / M(total)
Zg=[somm(zg^i* M^i) ] / M(total)

I only as data density and the length / surface of each single element of the structure

Re: Barycentre

Unread postPosted: 15 Feb 2014, 13:12
by marcoz
I wanted to ask this program:

How many elements are there?
ANSWER: for example, 5

If there are five elements creates a 2x5 matrix and enter the data

A1 D1
A2 D2
A3 D3
A4 D4
A5 D5

When I ask the program:

Calculate the mass of each element:

A1 * D1 = M1
A2 * D2 = M2
A3 * A3 = M3
A4 * D4 = M4
A5 * D5 = M5

I ask the program calculate the total mass

M (tot) = M1 + M2 + M3 + M4 + M5

I ask the program to insert an array always 3 x n.elementi and insert the centroid of each element


xg1 yg1 zg1
xg2 yg2 zg2
xg3 yg3 zg3
xg4 yg4 zg4
xg5 yg5 zg5


After I asked him: Now compute the centroid

Xg=[somm(xg^i* M^i) ] / M(total)= xg1*m1+xg2*m2+xg3*m3+xg4*m4+xg5*m5 / M(tot)
Yg=[somm(yg^i* M^i) ] / M(total)= .................
Zg=[somm(zg^i* M^i) ] / M(total)=.................

Re: Barycentre

Unread postPosted: 15 Feb 2014, 13:27
by pierrotdu18
Did you try the code I wrote for you?

It gives you M(total), I think you would be able to do the end as there is only one step left.

Re: Barycentre

Unread postPosted: 15 Feb 2014, 13:30
by marcoz
Thank you very much .... After I try and I'll know ... Now we all go to eat ...