Jump to content



Photo

Cplua Doubts


  • Please log in to reply
23 replies to this topic

#1 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 10 October 2006 - 09:16 PM

Ok I have two new questions...

1- For example how can I initialize a matrix mat mxn? m and n are inputs, for this, I can't put mat={{},{},{}}

2-

v={1.6667,2.3333,3.4444}
print(unpack(v)) --> 1.6667  2.3333  3.4444

I want change the format of the result of print(unpack(v)) to .2f for example, the result will be:

v={1.6667,2.3333,3.4444}
print(unpack(v)) --> 1.67  2.33  3.44

It is possible??

Thanks for all... :blink:

#2 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 10 October 2006 - 09:24 PM

1- You will have to create a loop for this...
For example:

function newMatrix(m,n)
  local mat = {}
  for i=1,m do
	mat[i] = {}
	for j=1,n do mat[i][j] = 0 end
  end
  return mat
end

m = tonumber(input("m="))
n = tonumber(input("n="))
mat = newMatrix(m,n)

2 - You can use printf() instead of print() :)

printf("%.2f\n", 1.6667) --> 1.67

Or you could use string.format() too to make some formated strings from numbers.

#3 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 11 October 2006 - 03:56 AM

Orwell, please give me a tutorial about debug commands.

#4 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 11 October 2006 - 12:19 PM

<_<

>>> http://www.lua.org/m...manual.html#5.9

#5 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 11 October 2006 - 01:32 PM

:P

#6 Guest_Guest_*

Guest_Guest_*
  • Guests

Posted 27 November 2006 - 07:49 PM

I want to mutiplicate a number and vector, I put:

require('LNAutils/MatMul')
e={1,0,0}
h=0.5
v=MatMul(h,{1,0,0})

But message error apears: attempt to index local 'A'. <_< What's wrong please?

#7 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 28 November 2006 - 04:59 PM

I want to mutiplicate a number and vector, I put

require('LNAutils/MatMul')
e={1,0,0}
h=0.5
v=MatMul(h,{1,0,0})
But message error apears: attempt to index local 'A'. <_< What's wrong please?

Hmmm, this is a question about LNA, not CPLua itself. Anyway, the answer to your question is simple: you are using the wrong function. MatMul stands for "matrix multiplication". Hence, Its arguments must be matrices or vectors, not scalars. There is no LNA function for multiplying a scalar with a vector. If you need to do so, write a loop like this:
v={}
for i=1,#e do
  v(i)=e(i)*h
end
or, even better:
v={}
for i,val in pairs(e) do
  v[i]=val*h
end
Of course, if you need multiplying a vector with a scalar frequently, you can also write a function implementing this.

#8 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 29 November 2006 - 01:59 PM

Thanks PAP, BTW I forgot log in when I wrote the question. ;)

#9 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 29 January 2007 - 12:25 AM

One doubt, when I put this:

m = tonumber(input("m="))

If I assign something like 8E-2, 2/2 or 8-5 to m, then m is nill, I only can put numbers (it's annoying if I want put 0.0000005), is there some form to solve this?

#10 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 30 January 2007 - 09:47 AM

This should be a solution to your problem:
require "cas"
m = cas(input("m=")) -- m is a CAS expression
m = m() -- calculate its numerical result
Or simply:
require "cas"
m = cas(input("m="))()
You will then be able to use every functions of the CAS (like sin(), roots, ...) :)
If the input expression is incorrect, the CAS will raise an error. You should prevent it with something like this:

require "cas"

function inputExpr(prompt)
  local test, v
  local function eval(s) return cas(s)() end 
  repeat test, v = pcall(eval, input(prompt))
  until test==true and v~=nil
  return v
end

m = inputExpr("m=")
print(m)

Btw I just realized that xpcall() does not seem to call the error handler correctly. I will have to investigate a little :huh:

#11 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 09 February 2007 - 03:57 PM

Is there some function like inverse of string.char, it is to say, you enter a simbol and it returns the number??

require('string')
n=70
print(string.char(n)) -> F	
-- it returns the simbol that correspond to that number

print(inverse_string.char(F)) -> it returns 70
-- where inverse_string.char is the function that I find

Exists it, or I should create ir? thanks

#12 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 09 February 2007 - 09:14 PM

string.byte() ;)

#13 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 05 June 2007 - 01:54 PM

Two things:
Can I write an imaginary number in CPLua? How?
In LNA can I find numericly the imaginary roots of an 4 and 3 degree equation? :blink:

#14 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 05 June 2007 - 10:11 PM

The Lua language has no built-in support for complex numbers.
However it is possible to simulate it by using tables with custom metatables ;)

#15 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 07 June 2007 - 06:50 AM

In LNA can I find numerically the imaginary roots of an 4 and 3 degree equation? :blink:

Sorry, you can't, at least not trivially. Like Orwell said, there is no built-in support for complex numbers in Lua (as in C/C++), so you need to simulate complex numbers by using tables. However, I don't think it is worth the effort, because in this case you have to "reinvent the wheel" (define complex number operations etc). Even then, LNA's root finding functions won't work "out of the box". In general, LNA is designed for real number arithmetics, and I don't even plan to include support for complex arithmetics in the future. The reason is simple: complex operations (such as integration, for example) is another story, so in practice support for complex arithmetics requires writing the complex-equivalent for all LNA's functions (which is not a trivial task). In addition, this must be done in a programming language which doesn't even "know" what a complex number is: it's a real nightmare, plus it's not really that important.

#16 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 23 June 2007 - 09:35 PM

How can I clear the screen of cplua... for example I put some pirints and the I use a function that delete all the content of screen, the next print will appears on the top of the screen.

#17 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 24 June 2007 - 07:30 PM

What about trying the "clear()" function? :lol:

#18 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 28 July 2007 - 08:29 PM

One thing...

a=cas(input('x= '))()

in CPLua 0.9D:
print(type(a)) --> number
in CPLua 0.9E:
print(type(a)) --> userdata

so in CPLua 0.9E if I put:

if a>0 then ... end

error attempt to compare number with userdata...

I need to put the function 'cas' because I need to input numbers like 1E-5

So how can I figure out it in CPLua 0.9E??

#19 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 29 July 2007 - 11:26 AM

:blink: Aaah that's right... I knew I forgot something <_<

This will be fixed in the next version.
Until then you can just use "a(0)" instead of "a()" ;)

#20 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 13 September 2007 - 09:31 AM

Is there any form to save a variable while a program is running? for example:

v={}
for i=1,5 do
  v[i]=input('input element')
end
save_function(v)  ???
and then load the v value in other time that I run the program. Is it possible?

#21 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 14 September 2007 - 06:13 PM

Why don't you take a look at the IO package? :)

require "io"
local f = io.file("myFold","myFile")
f:create("data", "myProg")

v={}
for i=1,5 do
  v[i]=input('input element')
end

f:open('w')
f:write(v)
f:close()
And to get it back:
require "io"
local f = io.file("myFold","myFile")
f:open('r')
v = f:read()
f:close()

for i=1,5 do
  print(v[i])
end
;)

#22 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 28 December 2007 - 06:33 PM

require('cas')
i=cas(input('i'))()
print(i)

In my CP if I put a number smaller than 0.01 then i=nill
In my PC emulator works ok

CPlua 0.9D

#23 diiego06

diiego06

    Newbie

  • Members
  • Pip
  • 17 posts
  • Gender:Male
  • Location:Cbba-Bolivia

  • Calculators:
    ClassPad 300

Posted 03 July 2008 - 03:23 PM

Hi, someone would be able to help me with the following problem: I wrote a function with "UI" that creates a window and sample some results... to finish the function I used the function _keydown:

function a()
...
wmat=ui.window{name="",expand=true,frame="thick",_keydown=function(self,K_EXE) ui.stop() end}
...
ui.start()
end
export{a=a}

When I call to the function since a program that does not use "UI" there is not problem but when I call it since another that utilizes "UI" in the classpad: a fatal exception error :blink: :banghead:

I think that I wrote wrong code... How it is utilized: ui.start () and ui.stop()? :)


the align comand in the lineedit and txtedit function does not work :)

#24 Jendem

Jendem

    Newbie

  • Members
  • Pip
  • 3 posts
  • Location:Porsgrunn, Norway

  • Calculators:
    Classpad 330
    fx-9860GII SD
    fx-9860G SDK

Posted 28 November 2009 - 04:43 PM

require('cas')
 i=cas(input('i'))()
 print(i)

In my CP if I put a number smaller than 0.01 then i=nill
In my PC emulator works ok

CPlua 0.9D




I've got the same problem. Have you found a solution?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users