Info

This question is closed. Reopen it to edit or answer.

What did I do wrong with my code to get this "^" error?

1 view (last 30 days)
Ethan Sehrt
Ethan Sehrt on 12 Jun 2016
Closed: MATLAB Answer Bot on 20 Aug 2021
I input an equation as y=((x^2)*sin(x))/exp(x) and defined x as x=logspace(0,6,7); in the script. When I run it, i get a message saying "error using ^. Inputs must be a scalar and a square matrix."
I'm trying to evaluate the different y value outputs with a range of x inputs as 1,10,100,1000,10000,100000,1000000 using a dot product feature

Answers (1)

the cyclist
the cyclist on 12 Jun 2016
Edited: the cyclist on 12 Jun 2016
Try
y=((x.^2).*sin(x))./exp(x)
Notice that I added some periods, to denote element-wise operations.
You might want to read this page about array and matrix operations.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!