Matrix On Lua
#1
Posted 13 April 2007 - 04:14 AM
On basic:
[[1,2][3,4]] => Mat_A
6 => Mat_A[1,1]
PrintNatural Mat_A
Thanks!!!!!!!!!!!!!!!
#2
Posted 13 April 2007 - 01:29 PM
how can i write this on Lua :
On basic:
[[1,2][3,4]] => Mat_A
6 => Mat_A[1,1]
PrintNatural Mat_A
Thanks!!!!!!!!!!!!!!!
A={{1,2},{3,4}} A[1][1]=6 for i=1,#A do print(unpack(A[i])) end
That's all..
#3
Posted 13 April 2007 - 06:40 PM
#4
Posted 23 April 2007 - 09:27 PM
require("cas")
Mat_A={}
d=input("Dimension of the Matrix:")
for i=1,d do
for j=1,d do
n=input("element "..i..","..j..":")
Mat_A[i][j]=n
end
end
#5
Posted 23 April 2007 - 10:16 PM
#6
Posted 24 April 2007 - 08:41 AM
require("cas")
Mat_A={}
d=input("Dimension of the Matrix:")
for i=1,d do
Mat_A[i] = {} -- initialise each row as a table before inserting new elements!
for j=1,d do
n=input("element "..i..","..j..":")
Mat_A[i][j]=n
end
end
#7
Posted 24 April 2007 - 10:40 AM
Anyway, don't use the CAS within CPLua, unless you need it disparately. In this case, you don't have any reason to do so: using the CAS will only make your program slower. Use CPLua's "tables" instead; they are weird, but at least the job can be done.
#8
Posted 24 November 2007 - 03:00 AM
When i uses this code
A={{1,2},{3,4}} A[1][1]=6 for i=1,#A do print(unpack(A[i])) endwith a matrix 6 x 6 complex it show a desaster. The element of the same row continuo on the next line, it is confuse.
Thanks
#9
Posted 26 November 2007 - 10:28 PM
I would suggest you to try the UI package, there is a nice "mathedit" component that you might use to display mathematical expressions like matrices and CAS formulas
#10
Posted 16 February 2008 - 04:57 PM
I would suggest you to try the UI package, there is a nice "mathedit" component that you might use to display mathematical expressions like matrices and CAS formulas
Orwell, I read the "uifunction.txt" but I could not find the function than make this possible.
I learned how to create a window (ui.windows{...}) and included some text editable or not (ui.textedit{..}) and other things, but what is the function that allow me to call the matrix?
Thanks!!!
#11
Posted 16 February 2008 - 08:53 PM
You can try something like this to display a matrix (or any other CAS expression):Orwell, I read the "uifunction.txt" but I could not find the function than make this possible.
I learned how to create a window (ui.windows{...}) and included some text editable or not (ui.textedit{..}) and other things, but what is the function that allow me to call the matrix?
Thanks!!!
require "ui" "cas" local win, me win = ui.window({name="Test", x=3, y=3, width=154, height=180}) me = ui.mathedit({x=0, y=0, width=152, parent=win}) me:setexpr(cas("[[1,2][3,4]]")) ui.button({text="Quit", x=122,y=79, parent=win, _clicked = function(self) ui.stop() end}) win:show(true) ui.start()
#12
Posted 17 February 2008 - 01:43 AM
attempt to call field "mathedit" (a nil value)
#13
Posted 17 February 2008 - 06:46 PM
#14
Posted 17 February 2008 - 09:12 PM
Thanks
#15
Posted 06 June 2013 - 04:11 AM
i mean i wanna run a program and i need to know how can i write some matrix?
for example 3*3 such as :
3 3 3
2 7 9
1 3 11
#16
Posted 06 June 2013 - 07:04 AM
There are already answers in the previous posts. It would look like M = { {3, 3, 3} , {2, 7, 9} , {1, 3, 11} } but I doubt you want to do that because matrix multiplication, etc need additional code. However LNA (download link) has some Matrix functions.
Alternatively you can use CP's native matrix handling like Orwell showed in post #11 in this topic.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users