Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working With Arrays #50

Open
Ephraim-Bryski opened this issue Sep 22, 2021 · 0 comments
Open

Working With Arrays #50

Ephraim-Bryski opened this issue Sep 22, 2021 · 0 comments

Comments

@Ephraim-Bryski
Copy link
Collaborator

I want a flexible approach for working with stuff like arrays, tables, and piecewise functions. Instead of following a set procedure, the user gives constraints and possible solutions are returned. This issue's just on arrays and iteration.

Approach

The Fibonacci numbers would usually be created iteratively like this:

Fib=[]
Fib[0]=0
Fib[1]=1
for (i=2;i<5;i++){
  Fib[i]=Fib[i-1]+Fib[i-2]
}

Instead I’m proposing something like this (these are all equations in a system, order does not matter):

Fib[0]=0
Fib[1]=1
Fib[i]=Fib[i-1]+Fib[i-2]
2<=i<5

Which can then be solved:
Fib=[0,1,1,2,3]

This allows you to use any piece of information. For example if you want to make something following the rules of Fibonacci numbers but the 5th element is 6 instead, you would just do:

Fib[0]=0
Fib[4]=6
Fib[i]=Fib[i-1]+Fib[i-2]
2<=i<5

This would return:
Fib=[0,3,3,6]

Application

This would be useful for engineering applications, where what is known and unknown varies from case to case. For example, the total pressure from soil layers is determined by adding the weight from each layer:

SoilLayers

p=rho*g*h
p_cum[i+1]=p_cum[i]+p[i]

If instead you wanted to find the depth required to get to a certain pressure with two soil layers, for example, you could do:

SoilLayers
rho=[1200,1700]
g=9.8
h=[15,depth-15]
p_cum[0]=0
p_cum[2]=20000

Basically, by building it around solving systems of equations, you are not constrained to a set of input or outputs as you would be using loops.

A similar approach could be used for piecewise functions and tables, which I could show in another issue.

I think the main challenge is to figure out exactly how the program should interpret arrays and how it should convert it to systems of equations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant