yameez
yameez

Reputation: 3

Error using sin. Not enough input arguments. Why is that so?

i am solving a mathematical problem and i can't continue do to the error.

I tried all constant with sin^2(x) yet its the same.

clear clc

t = 1:0.5:10;
theta = linspace(0,pi,19);

x = 2*sin(theta)

y = sin^2*(theta)*(t/4)

Error using sin Not enough input arguments.

Error in lab2t114 (line 9) y = sin^2*(theta)*(t/4)

Upvotes: 0

Views: 754

Answers (1)

Jimbo
Jimbo

Reputation: 3284

sin is a function so it should be called as sin(value) which in this case is sin(theta) It may help to consider writing everything in intermediate steps:

temp = sin(theta);
y = temp.^2 ...

Once this is done you can always insert lines from previous calculations into the next line, inserting parentheses to ensure order of operations doesn't mess things up. Note in this case you don't really need the parentheses.

y = (sin(theta)).^2; 

Finally, Matlab has matrix wise and element wise operations. The element wise operations start with a period '.' In Matlab you can look at, for example, help .* (element wise multiplication) and help * matrix wise calculation. For a scalar, like 2 in your example, this distinction doesn't matter. However for calculating y you need element-wise operations since theta and t are vectors (and in this case you are not looking to do matrix multiplication - I think ...)

t = 1:0.5:10;
theta = linspace(0,pi,19);

x = 2*sin(theta) %times scalar so no .* needed

sin_theta = sin(theta);
sin_theta_squared = sin_theta.^2; %element wise squaring needed since sin_theta is a vector
t_4 = t/4; %divide by scalar, this doesn't need a period
y = sin_theta_squared.*t_4; %element wise multiplication since both variables are arrays

OR

y = sin(theta).^2.*(t/4);

Also note these intermediate variables are largely for learning purposes. It is best not to write actual code like this since, in this case, the last line is a lot cleaner.

EDIT: Brief note, if you fix the sin(theta) error but not the .^ or .* errors, you would get some error like "Error using * Inner matrix dimensions must agree." - this is generally an indication that you forgot to use the element-wise operators

Upvotes: 1

Related Questions