solving a matrix 2x2 Shell script for? - linux

I was wondering if there is any way to solve a matrix 2x2 using shell script in Linux. I have created a simple code using Matlab and would like to to the same using shell script. The Matlab code is as follows;
R = 0.509515;
R1 = 0.559467;
R2 = 0.579594;
L = 0;
L1 = -0.08568;
L2 = 0.13974;
y = [R1-R;R2-R];
x = [L1^2 L1;L2^2 L2];
c = x\y;
Also, is there any way to create a linspace like that in Matlab for the following command;
x=linspace(L1,L2,20)
Thanks in advance for the kind help.

Related

How to create a sparse matrix using scipy.sparse.csr_matrix in scipy/numpy

I have to create a sparse matrix in python using a function similar to the Matlab function
S = sparse(i,j,v,m,n) where i, j, and v such that S(i(k),j(k)) = v(k) and the size of S is specified as m-by-n.
I have chosen the function scipy.sparse.csr_matrix to do this. My code is something like the following.
arg_shape=np.array([ndof,ndof])
K = csr_matrix((arg_data,(arg_x,arg_y)),shape=arg_shape)
here ndof=786432 and arg_data, arg_x, arg_y are numpy arrays and all of the same shape.i.e. (150994944,).
when I run this code, I get the following error:
ValueError: row index exceeds matrix dimensions
In Matlab the code looks like this and works:
K = sparse(arg_x,arg_y,arg_data, ndof, ndof);
Could anyone please help me with the following points:
1). Is scipy.sparse.csr_matrix a good replacement for the Matlab spare function.
2). If yes, what is the mistake I am making in the code?
Thank you very much.

Calculate multiple values in parallel

I have a function, xEuclid, for the extended euclidean algorithm, and I want to calculate 3 values using that function, being these values a = xEuclid(a1,b1), b = xEuclid(a2,b2) and c = xEuclid(a3,b3), using different parameters each call, so the idea to optimize the proces is to calculate a, b and c at the same time, in parallel.
I can't figure a way to solve it and unfortunately don't have the time to do the JuliaAcademy Parallel Programming tutorial, so please I need your help to solve it. Thank you!
Try the following
using Base.Threads: #spawn
a = #spawn xEuclid(a1,b1)
b = #spawn xEuclid(a2,b2)
c = #spawn xEuclid(a3,b3)
a = fetch(a); b = fetch(b); c = fetch(c)
This requires at least julia v1.3

Revit API: Direction of rebar spacing (Python)

I'm trying to multiply rebar in a slab using following methods:
(using Python script)
doc = DocumentManager.Instance.CurrentDBDocument
RS = Autodesk.Revit.DB.Structure
RebarType = MyRebarType
slab = MySlab
norm = XYZ(0,0,1)
bar = MyCurve
n = MyQuantity
s2 = RebarSpacing
hook_type = None
rebar = RS.Rebar.CreateFromCurves(doc,RS.RebarStyle.Standard,RebarType,hook_type,hook_type,slab,norm,bar,RS.RebarHookOrientation.Right,RS.RebarHookOrientation.Left,True,True)
rebar.get_Parameter(BuiltInParameter.REBAR_ELEM_LAYOUT_RULE).Set(3)
rebar.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS).Set(n)
rebar.get_Parameter(BuiltInParameter.REBAR_ELEM_BAR_SPACING).Set(s2)
The problem is that i cant define direction of my rebar spacing. It depends on rebar position in my slab.
Here is an example of how this code creates rebars
Any help would be appreciated.
Thank you
Just need to add one line:
rebar.GetShapeDrivenAccessor().BarsOnNormalSide = True

Making a randomly generated 2d map in python is taking too long to process all of the map generation

import random
l = "lava"
d = "dessert"
f = "forest"
v = "village"
s = "sect"
w = "water"
c = "city"
m = "mountains"
p = "plains"
t = "swamp"
map_list = [l,d,f,v,s,w,c,m,p,t]
map = []
for i in range(50):
map.append([])
def rdm_map(x):
for i in range(50):
map[x].append(random.choice(map_list))
def map_create():
x = 0
while x <= len(map):
rdm_map(x)
x + 1
map_create()
print(map[2][1])
I'm not getting anything for output not even an error code.I'm trying to create a randomly generated game map of descent size but when i went to run it nothing happened i'm thinking since my computer isn't that great its just taking way to long to process but i just wanted to post it on here to double check. If that is the issue is there a way to lessen the load without lessening the map size?
You have the following bugs:
Inside the map_create you must change x + 1 to x += 1. For this reason your script runs for ever.
After that you should change the while x <= len(map): to while x < len(map):. If you keep the previous, you will get a Index Error.
In any case, your code can be further improved. Please try to read some pages of the tutorial first.

Is there in prod() operator in gnuplot?

I am beginner with gnuplot and I am trying to plot the following function with gnuplot:
f(x) = sum[i=0:x](Pi[j=0:i](x+j-3))
where by Pi I mean the product operator:
Pi[j=0:i](x+j-3) = (x+0-3)*(x+1-3)...(x+i-3)
How can I write the gnuplot script for the Pi part?
if I didn't made mistakes you could use a recursive function:
prod(x,n,m) = (n<0) ? 1 : (x+n+m) * prod(x,n-1,m)
f(x) = sum[i=0:int(x)](prod(x,i,-3))
plot [0:3] f(x)
You can follow the recipe in this answer to use external functions, in this case Python. Create the external file function.py:
import sys
x=float(sys.argv[1])
i=int(sys.argv[2])
p = 1
for j in range(0,i+1):
p *= x + j - 3
print p
Now in gnuplot you can define the following product and sum functions:
prod(x,i) = real(system(sprintf("python function.py %g %i", x, i)))
f(x) = sum[i=0:int(x)](prod(x,i))
plot[0:3] f(x)
Note that x needs to be integer to be used to define the limits of the summation. Also note that calling external functions is quite slow.

Resources