Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # polynomial n-degree Chebyshev fit example
- # Juhani Kaukoranta 16.1.2024
- using Plots,Polynomials,ApproxFun
- n = 30; # pisteiden määrä
- x = range(-1,1,length=n); # x n arvoa
- f(x) = @. sqrt(1+x)*(sin(2*x)+cos(2*x)); # y n arvoa
- cheby = Fun(f); # ApproxFun -> Chebyshev-sovitus
- y = @. f(x); # original
- p = fit(ChebyshevT, x, y, 5); map(x -> round(x, digits=6), p);
- # p on Polynomials:n 5 degree Chebyshev-sovitus
- scatter(x,y,title="Julian Chebyshev-sovituksia\n
- f(x)=sqrt(x+1)*(sin(x)+cos(x))",label="original function")
- plot!(x,cheby.(x),label="Chebyshev from Polynomials",lw=2)
- plot!(x,p.(x),label ="Chebyshev 5 degr from ApproxFun",lw=2,ls=:dot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement