Uniformly Distribute numbers on for loop?
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Multivariate t Distribution dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!