Good morning, I'm a student of statistics and

I have to do this exercise : create a function for to calculate square of binomial.

I have written

binomio=function(z,y) {z^2+y*z*2+ y^2}

But this function isn't correct when z is unknown. For exemple when i want to calculate (x+2)^2 and I would like as a result (x^2+2*2*x+2^2)

Please help me...It is one of the first times that I'm using R studio.

# How can I create a function for binomial (a+b)^2?

If I understand your question right, using the multiplication operator `*`

between the variables may solve your problem.

```
binomio = function(z,y) {z^2+y*z*2+y^2}
binomio(3,4)
[1] 49
```

1 Like