Uniformly Distribute numbers on for loop?
Show older comments
Hello, I have some trouble with my code. The objective of it is to calculate
y(x) = x^3 - sin(x+pi/2) + cos^2*(2x)
for 100 values of x uniformly distributed between -1 and 3 using both a for loop, and vectorization, and to plot the two outputs.
Here is my code.
rng(0, 'Twister');
a = -1;
b = 3;
r = (b-a).*rand(100,1) + a;
pi = 3.14;
for x = r
y(x) = (x.^3) - sin*(x + (pi/2)) + cos.^2*(2*x);
end
plot(y(x))
I keep getting an error that says there is not enough input arguments for sin and cos. Can anyone help out?
Accepted Answer
More Answers (0)
Categories
Find more on Multivariate t Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!