JuliaApproximation / ApproxFun.jl

Julia package for function approximation
http://juliaapproximation.github.io/ApproxFun.jl/
Other
528 stars 70 forks source link

Multiplying CosSpace() / SinSpace() of different period leads error? #937

Closed yewalenikhil65 closed 2 months ago

yewalenikhil65 commented 3 months ago

Doing following multiplication of CosSpace/ SinSpace with another CosSpace()/SinSpace() of different period leads to following error. But i do need to find the multiplication. Can anybody please help here ?


julia> G = Fun(CosSpace(), rand(3)) 
Fun(CosSpace(【0.0,6.283185307179586❫), [0.587619, 0.499599, 0.616276]) 

julia> F = Fun(SinSpace(PeriodicSegment(0, pi)), rand(3));   # sin * cos

julia> Multiplication(F, CosSpace())*G 
ERROR: AssertionError: domain(f) == domain(sp) 
Stacktrace: 
 [1] Multiplication(f::Fun{SinSpace{PeriodicSegment{Float64}, Float64}, Float64, Vector{Float64}}, sp::CosSpace{PeriodicSegment{Float64}, Float64}) 
  @ ApproxFunFourier ~/.julia/packages/ApproxFunFourier/lFQDK/src/FourierOperators.jl:222 
 [2] top-level scope 
  @ REPL[11]:1

julia> F = Fun(CosSpace(PeriodicSegment(0, pi)), rand(3));   # cos* cos

julia> Multiplication(F, CosSpace())*G
ERROR: Domain mismatch: cannot multiply function on 【0.0,3.141592653589793❫ to function on 【0.0,6.283185307179586❫
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] ConcreteMultiplication
   @ ApproxFunBase ~/.julia/packages/ApproxFunBase/clvO0/src/Operators/banded/Multiplication.jl:23 [inlined]
 [3] Multiplication(f::Fun{CosSpace{PeriodicSegment{Float64}, Float64}, Float64, Vector{Float64}}, sp::CosSpace{PeriodicSegment{Float64}, Float64})
   @ ApproxFunFourier ~/.julia/packages/ApproxFunFourier/lFQDK/src/FourierOperators.jl:218
 [4] top-level scope
   @ REPL[98]:1
yewalenikhil65 commented 3 months ago

Just to mention my purpose I wished to create series in following way

a= rand(3);  b= rand(3);  # typically arrays of of n elements

# simplify following multiplication into another cosine series of period 2pi
  (a[1] + a[2]*cos(θ) + a[3]*cos)(2θ) + ...)*(b[1] + b[2]*cos(2θ) + b[3]*cos(4θ) + ...)
mzaffalon commented 3 months ago

If you need the analytical solution, you can use SymPy.jl.

yewalenikhil65 commented 3 months ago

If you need the analytical solution, you can use SymPy.jl.

I don't really want a symbolic solution.. Just the coefficients of the resulting CosSpace when the multiplying CosSpaces have different period

The theta I wrote in earlier comment is just for explanation

dlfivefifty commented 2 months ago

Just re-expand the one with the larger period in the space with the smaller period

yewalenikhil65 commented 2 months ago

Just re-expand the one with the larger period in the space with the smaller period

Do you mean something like this ?

julia> using ApproxFun

julia> G = Fun(CosSpace(), rand(3)) ;

julia> G
Fun(CosSpace(【0.0,6.283185307179586❫), [0.642775, 0.257448, 0.915413])

julia> F = Fun(CosSpace(), [1,0.0, rand(), 0.0, rand() , 0.0, rand()])
Fun(CosSpace(【0.0,6.283185307179586❫), [1.0, 0.0, 0.297021, 0.0, 0.476742, 0.0, 0.711284])

julia> F*G

Fun(CosSpace(【0.0,6.283185307179586❫), [0.778723, 0.295682, 1.32454, 0.0996018, 0.767945, 0.152927, 0.675403, 0.0915593, 0.325559])
yewalenikhil65 commented 2 months ago

@dlfivefifty I am closing this. I managed to do finally as per my previous command