Need help with for loop and ploting.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Stephen
el 2 de Nov. de 2014
Respondida: Star Strider
el 2 de Nov. de 2014
This is the question
Problem 1: Use “for loop” write MATLAB program to calculate function f1, and plot function f1 = cos(x1), for x1 in the domain [0, pi]. (Choose increment of x1 to be 0.2)
Please include (a) Flow Chart (b) Matlab Script (c) A copy of the final Output (plot)
this is what I was able to come up with, can't seem to figure this out with a for loop.
for x1=0:.1:pi f1=cos(x1); f1=[x1,f1];
end hold on plot(x1,f1,'g')
What am I missing?
0 comentarios
Respuesta aceptada
Star Strider
el 2 de Nov. de 2014
I would code it differently, but there are two changes you would need to make in your code:
f1 = []; % Initialise ‘f1’ As Empty
for x1=0:.1:pi
f=cos(x1); % Use a Different Variable Here
f1=[f1 f]; % Concatanate the New Value With Previous
end
Reproduce your ‘x1’ vector in your for loop statement to plot your function.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!