# Error with sin and cos function after update NeuralPDE

**URL:** https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154
**Category:** General Usage
**Tags:** question, package, jupyter, new-version
**Created:** [July 27, 2023, 1:06pm UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154 "2023-07-27T13:06:33Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)
#### Post date: [July 27, 2023, 1:06pm UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154/1 "2023-07-27T13:06:33Z")

</div>

I have updated to the latest version of package NeuralPDE and used the `res = Optimization.solve(prob,OptimizationOptimJL.BFGS(); callback = callback, maxiters = 1500)` to solve the ODE system on Jupyter notebook. I got the message:

```julia
MethodError: no method matching cos(::Matrix{Float64})
You may have intended to import Base.cos

```

This issue did not occur when I used the older version (I forgot the exact version that I used before the update).  
How could I fix this error?

---

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [July 27, 2023, 1:29pm UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154/2 "2023-07-27T13:29:48Z")

</div>

Does this happen after a fresh start? It is possible you have re-defined `cos` somewhere that would give this error. For example, this works:

```julia
C:\Users\User>julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.9.2 (2023-07-05)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> A=rand(5,5)
5×5 Matrix{Float64}:
 0.909718 0.108619 0.995858 0.234943 0.0742485
 0.965059 0.638944 0.0691136 0.618132 0.436923
 0.74908 0.351674 0.0514817 0.66934 0.992477
 0.211503 0.774835 0.134928 0.632693 0.0331376
 0.226476 0.294484 0.88037 0.554454 0.154767

julia> cos(A)
5×5 Matrix{Float64}:
  0.427955 -0.166231 -0.331578 -0.324861 -0.400794
 -0.560274 0.641195 -0.496704 -0.388002 -0.101208
 -0.394016 -0.35062 0.376286 -0.438875 -0.0776861
 -0.367901 -0.389009 -0.0493614 0.654608 -0.148705
 -0.385263 -0.322394 -0.0887973 -0.417086 0.608369

```

but if you first defined some new method for `cos`, it fails:

```julia
C:\Users\User>julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.9.2 (2023-07-05)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> cos(A::String) = A # just any definition
cos (generic function with 1 method)

julia> cos(rand(5, 5))
ERROR: MethodError: no method matching cos(::Matrix{Float64})
You may have intended to import Base.cos

Closest candidates are:
  cos(::String)
   @ Main REPL[1]:1

Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

```

(P.S. `cos(A)` is compute the matrix cosine of `A` rather than `cos` of each element of `A`, which is `cos.(A)`, just in case that’s what you intend to do.)

---

<div class="post-metadata">

### Author: ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)
#### Post date: [July 27, 2023, 1:57pm UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154/3 "2023-07-27T13:57:30Z")

</div>

But before I update all packages and Julia version 1.9.2, this error did not occur. Actually, I use the cos and sin function for variables in the ODE problem and use NeuralPDE to solve it.

---

<div class="post-metadata">

### Author: ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)
#### Post date: [July 27, 2023, 7:25pm UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154/4 "2023-07-27T19:25:57Z")

</div>

In the model, if I remove the equation with the sin and cos functions it can run well.  
the equations with sin and cos are:

```julia
D(omega1(t)) ~ (TM1(t)-(E1^2*Y1[1,1].re + E1*E2*sin(delta1(t)-delta2(t))*Y1[1,2].im + E1*E2*cos(delta1(t)-delta2(t))*Y1[1,2].re + E1*E3*sin(delta1(t)-delta3(t))*Y1[1,3].im + 
        E1*E3*cos(delta1(t)-delta3(t))*Y1[1,3].re))/(2*data["H"][1])*omega_s,
    #
D(omega2(t)) ~ (TM2(t)-(E2^2*Y1[2,2].re + E1*E2*sin(delta2(t)-delta1(t))*Y1[2,1].im + E1*E2*cos(delta2(t)-delta1(t))*Y1[2,1].re + E2*E3*sin(delta2(t)-delta3(t))*Y1[2,3].im + 
        E2*E3*cos(delta2(t)-delta3(t))*Y1[2,3].re))/(2*data["H"][2])*omega_s,
    #
D(omega3(t)) ~ (TM3(t)-(E3^2*Y1[3,3].re + E3*E1*sin(delta3(t)-delta1(t))*Y1[3,1].im + E3*E1*cos(delta3(t)-delta1(t))*Y1[3,1].re + E3*E2*sin(delta3(t)-delta2(t))*Y1[3,2].im + 
        E3*E2*cos(delta3(t)-delta2(t))*Y1[3,2].re))/(2*data["H"][3])*omega_s.

```

how could I fix this error?

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [July 28, 2023, 11:24am UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154/5 "2023-07-28T11:24:55Z")

</div>

Try changing those to `cos.`? @xtalax is this supposed to broadcast automatically?

---

<div class="post-metadata">

### Author: ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)
#### Post date: [July 28, 2023, 11:58am UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154/6 "2023-07-28T11:58:06Z")

</div>

yes and got the same message:

```julia
D(omega1(t)) ~ (TM1(t) - (E1^2*Y1[1,1].re + E1*E2*sin.(delta1(t)-delta2(t))*Y1[1,2].im + E1*E2*cos.(delta1(t)-delta2(t))*Y1[1,2].re + E1*E3*sin.(delta1(t)-delta3(t))*Y1[1,3].im + 
        E1*E3*cos.(delta1(t)-delta3(t))*Y1[1,3].re))/(2*data["H"][1])*omega_s,
    #
    D(omega2(t)) ~ (TM2(t) - (E2^2*Y1[2,2].re + E1*E2*sin.(delta2(t)-delta1(t))*Y1[2,1].im + E1*E2*cos.(delta2(t)-delta1(t))*Y1[2,1].re + E2*E3*sin.(delta2(t)-delta3(t))*Y1[2,3].im + 
        E2*E3*cos.(delta2(t)-delta3(t))*Y1[2,3].re))/(2*data["H"][2])*omega_s,
    #
    D(omega3(t)) ~ (TM3(t) - (E3^2*Y1[3,3].re + E3*E1*sin.(delta3(t)-delta1(t))*Y1[3,1].im + E3*E1*cos.(delta3(t)-delta1(t))*Y1[3,1].re + E3*E2*sin.(delta3(t)-delta2(t))*Y1[3,2].im + 
        E3*E2*cos.(delta3(t)-delta2(t))*Y1[3,2].re))/(2*data["H"][3])*omega_s];

```

```julia
MethodError: no method matching cos(::Matrix{Float64})
You may have intended to import Base.cos

Closest candidates are:
  cos(::ForwardDiff.Dual{T}) where T
   @ ForwardDiff C:\Users\htran\.julia\packages\ForwardDiff\vXysl\src\dual.jl:238
  cos(::DualNumbers.Dual)
   @ DualNumbers C:\Users\htran\.julia\packages\DualNumbers\5knFX\src\dual.jl:327
  cos(::Float64)
   @ NaNMath C:\Users\htran\.julia\packages\NaNMath\ceWIc\src\NaNMath.jl:9
  ...MethodError: no method matching cos(::Matrix{Float64})
You may have intended to import Base.cos

Closest candidates are:
  cos(::ForwardDiff.Dual{T}) where T
   @ ForwardDiff C:\Users\htran\.julia\packages\ForwardDiff\vXysl\src\dual.jl:238
  cos(::DualNumbers.Dual)
   @ DualNumbers C:\Users\htran\.julia\packages\DualNumbers\5knFX\src\dual.jl:327
  cos(::Float64)
   @ NaNMath C:\Users\htran\.julia\packages\NaNMath\ceWIc\src\NaNMath.jl:9
  ...

```

---

<div class="post-metadata">

### Author: ![xtalax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xtalax/32/35293_2.png) [@xtalax](https://discourse.julialang.org/u/xtalax)
#### Post date: [July 28, 2023, 2:59pm UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154/7 "2023-07-28T14:59:09Z")

</div>

Yes, this should be automatically broadcasting, the ` __dot__ ` function that does this seems really picky about when it wants to work properly however.

I’ll add a test for this and check on 1.9.2

---

<div class="post-metadata">

### Author: ![joshiamit11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshiamit11/32/203946_2.png) [@joshiamit11](https://discourse.julialang.org/u/joshiamit11)
#### Post date: [November 15, 2023, 9:16pm UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154/8 "2023-11-15T21:16:52Z")

</div>

Was this error resolved? I get this error while running the neuralPDE example from documentation. [Introduction to NeuralPDE for PDEs · NeuralPDE.jl](https://docs.sciml.ai/NeuralPDE/stable/tutorials/pdesystem/)

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [November 15, 2023, 9:50pm UTC](https://discourse.julialang.org/t/error-with-sin-and-cos-function-after-update-neuralpde/102154/9 "2023-11-15T21:50:41Z")

</div>

It was solved a few months back. What versions are you using?
