Advertisement
jukaukor

polynomial_fit_chebyshev.jl

Jan 18th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # polynomial n-degree Chebyshev fit example
  2. # Juhani Kaukoranta 16.1.2024
  3. using Plots,Polynomials,ApproxFun
  4. n = 30; # pisteiden määrä
  5. x = range(-1,1,length=n); # x n arvoa
  6. f(x) = @. sqrt(1+x)*(sin(2*x)+cos(2*x)); # y n arvoa
  7. cheby = Fun(f); # ApproxFun -> Chebyshev-sovitus
  8. y = @. f(x); # original
  9. p = fit(ChebyshevT, x, y, 5); map(x -> round(x, digits=6), p);
  10. # p on Polynomials:n 5 degree Chebyshev-sovitus
  11. scatter(x,y,title="Julian Chebyshev-sovituksia\n
  12. f(x)=sqrt(x+1)*(sin(x)+cos(x))",label="original function")
  13. plot!(x,cheby.(x),label="Chebyshev from Polynomials",lw=2)
  14. plot!(x,p.(x),label ="Chebyshev 5 degr from ApproxFun",lw=2,ls=:dot)
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement