# Julia Simple Plot Problem (x^4)

**URL:** <https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549>\
**Category:** General Usage\
**Created:** [August 24, 2017, 10:29pm UTC](https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549 "2017-08-24T22:29:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Romero\_Azzalini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/romero_azzalini/32/10325_2.png) [@Romero\_Azzalini](https://discourse.julialang.org/u/Romero_Azzalini)\
**Post date:** [August 24, 2017, 10:29pm UTC](https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549/1 "2017-08-24T22:29:06Z")

</div>

Hi,  
why isn’t it working? g(x) works, g2(x) fails aswell.

 ![juliaprob](https://global.discourse-cdn.com/julialang/original/3X/0/7/072c9bd73f6882efc5e0323b36acea8689743988.png)

Best,  
Hannes!

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 24, 2017, 10:30pm UTC](https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549/2 "2017-08-24T22:30:54Z")

</div>

Welcome, @Romero_Azzalini! The link you posted is broken. In general, the best way to get help is to paste complete and stand-alone code directly into the post. Surround the code with triple backticks in order for it to be formatted properly.

````julia
```
code here
```

````

---

<div class="post-metadata">

**Author:** ![Romero\_Azzalini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/romero_azzalini/32/10325_2.png) [@Romero\_Azzalini](https://discourse.julialang.org/u/Romero_Azzalini)\
**Post date:** [August 24, 2017, 10:41pm UTC](https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549/3 "2017-08-24T22:41:48Z")

</div>

sorry, now you can see it 😉

---

<div class="post-metadata">

**Author:** ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)\
**Post date:** [August 24, 2017, 10:58pm UTC](https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549/4 "2017-08-24T22:58:53Z")

</div>

You’re not doing the exponentiation elementwise (`^` vs `.^`) in `f` and `g2`.

```julia
julia> x = linspace(0,10,2)
0.0:10.0:10.0

julia> x^4
ERROR: DimensionMismatch("Cannot multiply two vectors")
Stacktrace:
 [1] power_by_squaring(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Int64) at ./intfuncs.jl:175
 [2] literal_pow(::Base.#^, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Type{Val{4}}) at ./intfuncs.jl:205

julia> x.^4
2-element Array{Float64,1}:
     0.0
 10000.0

```

---

<div class="post-metadata">

**Author:** ![Romero\_Azzalini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/romero_azzalini/32/10325_2.png) [@Romero\_Azzalini](https://discourse.julialang.org/u/Romero_Azzalini)\
**Post date:** [August 24, 2017, 11:22pm UTC](https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549/5 "2017-08-24T23:22:09Z")

</div>

thx, it works now! is it a type problem?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 25, 2017, 12:04am UTC](https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549/6 "2017-08-25T00:04:18Z")

</div>

Kind-of, but has more to do with linear algebra than types. Multiplication simply isn’t defined between two vectors. Exponentiation by integers is just repeated multiplications. But you don’t want to exponentiate the _whole vector_, you just want to exponentiate each of its elements. That’s the difference between `x^4` and `x.^4`.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 25, 2017, 2:07am UTC](https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549/7 "2017-08-25T02:07:39Z")

</div>

If you are coming from Python/NumPy, you probably are used to exponentiation (`**`) and multiplication (`*`) always being elementwise; to get the linear-algebra meaning of these operations you need to do `numpy.matrix_power` and `numpy.dot`.

In Julia, exponentiation (`^`) and multiplication (`*`) are the linear-algebra meaning, and you use `.^` and `.*` for the elementwise/broadcasting meaning.

However, this is more than just a spelling difference. The dot `.` has a deeper meaning in Julia: it allows you to turn _any_ function or operator in Julia into an elementwise operation. Moreover, because you indicate that it is elementwise at a syntactic level, the language can [fuse multiple elementwise operations into a single loop](https://julialang.org/blog/2017/01/moredots).

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [August 25, 2017, 11:55am UTC](https://discourse.julialang.org/t/julia-simple-plot-problem-x-4/5549/8 "2017-08-25T11:55:03Z")

</div>

We could easily change the error to:

```julia
ERROR: DimensionMismatch("Cannot multiply two vectors. Maybe you had element-wise (done with a dot) in mind?")

```

> [@mbauman](#):
>
> Multiplication simply isn’t defined between two vectors.

Right. Now that we have the new Row and Column vectors, and such multiplied an the exception, then possibly that can help in cases to make more helpful error messages?

```julia
 julia> [1 2]^2 # here helpful "square matrix wanted", could be done for the power operator on Row or Column vectors
ERROR: DimensionMismatch("matrix A has dimensions (1,2), matrix B has dimensions (1,2)")

julia> [1 2]*[1 2]' # while this works
1×1 Array{Int64,2}:
 5

```
