import numpy as np
x0 = float(input("Unesite prvo rjesenje x_0 karakteristicne jednadzbe: "))
x1 = float(input("Unesite drugo rjesenje x_1 karakteristicne jednadzbe: "))
x2 = float(input("Unesite trece rjesenje x_2 karakteristicne jednadzbe: "))
a0 = float(input("Unesite vrijednost nultog clana niza a_0: "))
a1 = float(input("Unesite vrijednost prvog clana niza a_1: "))
a2 = float(input("Unesite vrijednost drugog clana niza a_2: "))
n = int(input("Unesite redni broj n trazenog clana niza: "))
A = np.array([[1,1,1],
[x0, x1, x2],
[x0*x0, x1*x1, x2*x2]])
B = np.array([a0, a1, a2])
invA = np.linalg.inv(A)
x = np.dot(invA, B)
an1 = x[0]*pow(x0, n)+x[1]*pow(x1, n)+x[2]*pow(x2, n) #prvi zadatak - pomoću formule za opće rješenje homogene rekurzivne relacije
print("Vrijednost n-tog clana niza pomocu formule: ", int(an1))
# tu si moram napisat postupak kak sam do ovih koeficijenata dosao ako budu gledali kod
koef1=-(-x2-x1-x0)
koef2=-((x1+x0)*x2+x0*x1)
koef3=-(-x0*x1*x2)
def recursive(n): #drugi zadatak - rekurzivno
if(n==0):
return a0
elif(n==1):
return a1
elif(n==2):
return a2
else:
return koef1*recursive(n-1) + koef2*recursive(n-2) + koef3*recursive(n-3)
an2 = recursive(n)
print("Vrijednost n-tog clana niza iz rekurzije: ", int(an2))
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}