lugar geometrico raiz
DownloadTélécharger
Actions
Vote :
ScreenshotAperçu

Informations
Catégorie :Category: nCreator TI-Nspire
Auteur Author: TrueDuck
Type : Classeur 3.0.1
Page(s) : 1
Taille Size: 6.07 Ko KB
Mis en ligne Uploaded: 08/09/2025 - 21:25:28
Uploadeur Uploader: TrueDuck (Profil)
Téléchargements Downloads: 1
Visibilité Visibility: Archive publique
Shortlink : https://tipla.net/a4835598
Type : Classeur 3.0.1
Page(s) : 1
Taille Size: 6.07 Ko KB
Mis en ligne Uploaded: 08/09/2025 - 21:25:28
Uploadeur Uploader: TrueDuck (Profil)
Téléchargements Downloads: 1
Visibilité Visibility: Archive publique
Shortlink : https://tipla.net/a4835598
Description
Fichier Nspire généré sur TI-Planet.org.
Compatible OS 3.0 et ultérieurs.
<<
-- Root Locus (Lugar Geométrico de las Raíces) para TI-Nspire -- Ingresas coeficientes de N(s) y D(s) (orden descendente), Kmax y pasos. -- Requiere CAS (CX CAS). Usa CAS 'zeros()' para raíces del polinomio. -- Por: ChatGPT platform.apilevel = '2.7' local gc -- graphics context local num = {} -- coef N(s) local den = {} -- coef D(s) local Kmax = 100 local nSteps = 100 local Ks = {} local rootsPerK = {} -- tabla: { [kIndex] = { {re,im}, ... } } local currentIdx = 1 ---------------------------------------------------------------- -- Helpers ---------------------------------------------------------------- local function trim(s) return (s:gsub("^%s+",""):gsub("%s+$","")) end local function splitCSV(s) local t = {} for token in string.gmatch(s, '([^,]+)') do table.insert(t, tonumber(trim(token))) end return t end -- from {a_n,...,a0} build CAS poly string a_n*s^n + ... + a0 local function polyToString(coefs, var) local n = #coefs local terms = {} for i,c in ipairs(coefs) do local pow = n - i if c ~= 0 then local coefStr if math.abs(c) == 1 and pow > 0 then coefStr = (c < 0) and "-" or "" else coefStr = tostring(c) end local term if pow == 0 then term = coefStr elseif pow == 1 then term = coefStr .. var else term = coefStr .. var .. "^" .. pow end table.insert(terms, term) end end if #terms == 0 then return "0" end local poly = terms[1] for i=2,#terms do local t = terms[i] if string.sub(t,1,1) == "-" then poly = poly .. t -- already has minus else poly = poly .. "+" .. t end end return poly end -- D_K(s) = D(s) + K*N(s) local function DK_string(K) -- iguala grados rellenando con ceros local nD, nN = #den, #num local n = math.max(nD, nN) local D, N = {}, {} for i=1,n do D[i] = den[i - (n - nD)] or 0 N[i] = num[i - (n - nN)] or 0 end -- coefs de D + K*N local coefs = {} for i=1,n do coefs[i] = D[i] + K * N[i] end return polyToString(coefs, "s") end -- pide raíces del polinomio a CAS: zeros(poly, s) local function rootsCAS(polyStr) -- devoluciones típicas: lista {a+bi, c+di, ...} o {a, b, ...} local cmd = "zeros(" .. polyStr .. ", s)" local out = math.eval(cmd) -- Convertir a tabla de {re,im} local r = {} -- Quitar llaves out = tostring(out or "") out = out:gsub("[%{%}]", "") -- separar por comas de nivel top (aprox) for token in string.gmatch(out, '([^,]+)') do token = trim(token) -- form "a+bi" o "a-bi" o solo "a" local re, im = 0, 0 if token:find("i") then token = token:gsub("%s","") token = token:gsub("","-") -- por si sale signo largo -- reemplazar a+bi por re,im local sign = 1 local pos = token:find("[+%-][^+%-]*i$") if pos then local reStr = string.sub(token,1,pos-1) local imStr = string.sub(token,pos,#token-1) re = tonumber(reStr) or 0 im = tonumber(imStr) or 0 else -- algo como "bi" local imStr = token:gsub("i","") im = tonumber(imStr) or 0 re = 0 end else re = tonumber(token) or 0 im = 0 end table.insert(r, {re, im}) end return r end local function computeAll() Ks, rootsPerK = {}, {} for i=1,nSteps do local K = (i-1) * (Kmax/(nSteps-1)) Ks[i] = K local poly = DK_string(K) local r = rootsCAS(poly) rootsPerK[i] = r end currentIdx = 1 end ---------------------------------------------------------------- -- UI entrada de datos ---------------------------------------------------------------- local state = "input" -- "input" or "plot" local input = { num = "", den = "", Kmax = "100", steps = "100", msg = "Ingresa coeficientes (descendentes). Ej: num: 1,1 den: 1,5,-6,0" } function on.create() gc = platform.gc() end function on.paint(gc) gc:clear() if state == "input" then gc:setFont("sansserif","r",12) gc:drawString("LGR - Ingrese datos", 10, 10) gc:drawString("Numerador N(s) (ej: 1,1)", 10, 40) gc:drawRect(10,55,300,20) gc:drawString(input.num, 15, 58) gc:drawString("Denominador D(s) (ej: 1,5,-6,0)", 10, 90) gc:drawRect(10,105,300,20) gc:drawString(input.den, 15, 108) gc:drawString("Kmax", 10, 140); gc:drawRect(60,135,80,20); gc:drawString(input.Kmax, 65, 138) gc:drawString("Pasos", 160, 140); gc:drawRect(210,135,80,20); gc:drawString(input.steps, 215, 138) gc:drawString("Enter: calcular | Tab: cambiar campo", 10, 175) gc:drawString(input.msg, 10, 200) else -- plot local w,h = gc:getWindowSize() gc:setFont("sansserif","r",11) gc:drawString("LGR (Ä/º para K) K="..string.format("%.3g", Ks[currentIdx] or 0), 10, 10) -- Ejes local left, right = -10, 10 local bottom, top = -10, 10 local function X(x) return 40 + (x - left) * (w-80) / (right-left) end local function Y(y) return h-40 - (y - bottom
[...]
>>
Compatible OS 3.0 et ultérieurs.
<<
-- Root Locus (Lugar Geométrico de las Raíces) para TI-Nspire -- Ingresas coeficientes de N(s) y D(s) (orden descendente), Kmax y pasos. -- Requiere CAS (CX CAS). Usa CAS 'zeros()' para raíces del polinomio. -- Por: ChatGPT platform.apilevel = '2.7' local gc -- graphics context local num = {} -- coef N(s) local den = {} -- coef D(s) local Kmax = 100 local nSteps = 100 local Ks = {} local rootsPerK = {} -- tabla: { [kIndex] = { {re,im}, ... } } local currentIdx = 1 ---------------------------------------------------------------- -- Helpers ---------------------------------------------------------------- local function trim(s) return (s:gsub("^%s+",""):gsub("%s+$","")) end local function splitCSV(s) local t = {} for token in string.gmatch(s, '([^,]+)') do table.insert(t, tonumber(trim(token))) end return t end -- from {a_n,...,a0} build CAS poly string a_n*s^n + ... + a0 local function polyToString(coefs, var) local n = #coefs local terms = {} for i,c in ipairs(coefs) do local pow = n - i if c ~= 0 then local coefStr if math.abs(c) == 1 and pow > 0 then coefStr = (c < 0) and "-" or "" else coefStr = tostring(c) end local term if pow == 0 then term = coefStr elseif pow == 1 then term = coefStr .. var else term = coefStr .. var .. "^" .. pow end table.insert(terms, term) end end if #terms == 0 then return "0" end local poly = terms[1] for i=2,#terms do local t = terms[i] if string.sub(t,1,1) == "-" then poly = poly .. t -- already has minus else poly = poly .. "+" .. t end end return poly end -- D_K(s) = D(s) + K*N(s) local function DK_string(K) -- iguala grados rellenando con ceros local nD, nN = #den, #num local n = math.max(nD, nN) local D, N = {}, {} for i=1,n do D[i] = den[i - (n - nD)] or 0 N[i] = num[i - (n - nN)] or 0 end -- coefs de D + K*N local coefs = {} for i=1,n do coefs[i] = D[i] + K * N[i] end return polyToString(coefs, "s") end -- pide raíces del polinomio a CAS: zeros(poly, s) local function rootsCAS(polyStr) -- devoluciones típicas: lista {a+bi, c+di, ...} o {a, b, ...} local cmd = "zeros(" .. polyStr .. ", s)" local out = math.eval(cmd) -- Convertir a tabla de {re,im} local r = {} -- Quitar llaves out = tostring(out or "") out = out:gsub("[%{%}]", "") -- separar por comas de nivel top (aprox) for token in string.gmatch(out, '([^,]+)') do token = trim(token) -- form "a+bi" o "a-bi" o solo "a" local re, im = 0, 0 if token:find("i") then token = token:gsub("%s","") token = token:gsub("","-") -- por si sale signo largo -- reemplazar a+bi por re,im local sign = 1 local pos = token:find("[+%-][^+%-]*i$") if pos then local reStr = string.sub(token,1,pos-1) local imStr = string.sub(token,pos,#token-1) re = tonumber(reStr) or 0 im = tonumber(imStr) or 0 else -- algo como "bi" local imStr = token:gsub("i","") im = tonumber(imStr) or 0 re = 0 end else re = tonumber(token) or 0 im = 0 end table.insert(r, {re, im}) end return r end local function computeAll() Ks, rootsPerK = {}, {} for i=1,nSteps do local K = (i-1) * (Kmax/(nSteps-1)) Ks[i] = K local poly = DK_string(K) local r = rootsCAS(poly) rootsPerK[i] = r end currentIdx = 1 end ---------------------------------------------------------------- -- UI entrada de datos ---------------------------------------------------------------- local state = "input" -- "input" or "plot" local input = { num = "", den = "", Kmax = "100", steps = "100", msg = "Ingresa coeficientes (descendentes). Ej: num: 1,1 den: 1,5,-6,0" } function on.create() gc = platform.gc() end function on.paint(gc) gc:clear() if state == "input" then gc:setFont("sansserif","r",12) gc:drawString("LGR - Ingrese datos", 10, 10) gc:drawString("Numerador N(s) (ej: 1,1)", 10, 40) gc:drawRect(10,55,300,20) gc:drawString(input.num, 15, 58) gc:drawString("Denominador D(s) (ej: 1,5,-6,0)", 10, 90) gc:drawRect(10,105,300,20) gc:drawString(input.den, 15, 108) gc:drawString("Kmax", 10, 140); gc:drawRect(60,135,80,20); gc:drawString(input.Kmax, 65, 138) gc:drawString("Pasos", 160, 140); gc:drawRect(210,135,80,20); gc:drawString(input.steps, 215, 138) gc:drawString("Enter: calcular | Tab: cambiar campo", 10, 175) gc:drawString(input.msg, 10, 200) else -- plot local w,h = gc:getWindowSize() gc:setFont("sansserif","r",11) gc:drawString("LGR (Ä/º para K) K="..string.format("%.3g", Ks[currentIdx] or 0), 10, 10) -- Ejes local left, right = -10, 10 local bottom, top = -10, 10 local function X(x) return 40 + (x - left) * (w-80) / (right-left) end local function Y(y) return h-40 - (y - bottom
[...]
>>