Borrar filtros
Borrar filtros

How to make a vector where each element=5 and 100 elements long?

17 visualizaciones (últimos 30 días)
We have a given function: Y1 = 5 – (1/x).
Now (1) I have to use linspace to create an equidistant x-vector from 1 to 100 with 100 elements .
(2) Make a corresponding Y1 vector (use ‘./’ for element-wise division) using the x-vector and the formula for Y1.
(3) Make a corresponding Y2 vector (each element = 5 and 100 elements long ). [It was my main point of the question]
(4) In the same graph, plot Y1 and Y2 against x ! Make title, linecolors, axislabels, tics, grids etc to get a really nice figure. (To determine from the figure, approximately, from which x-value Y2 is a good approximation to Y1?)
Note: I solved them like this but I dont know if they are correct or not.
hold on;
hold off;

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Mayo de 2014
If each element of Y2 is supposed to have a value of 5 and be a hundred elements long, you'd want this
Y2 = 5 * ones(1, 100); % or y2 whichever case you want to use.
  2 comentarios
Jabir Al Fatah
Jabir Al Fatah el 30 de Mayo de 2014
please i want the complete answer of my questions step by step.
Image Analyst
Image Analyst el 30 de Mayo de 2014
But it's your homework, not mine. You did 1 and 2, and I did #3 for you. All you have to do for step 4 is to call title() and xlabel(), etc.
plot(x,y2, 'LineColor', 'r', 'LineWidth', 3);
title('This is my plot', 'FontSize', 30);
ylabel('Y and Y2', 'FontSize', 30);
grid on;
% Function to maximize the window via undocumented Java call.
% Reference:
FigurejFrame = get(handle(gcf),'JavaFrame');
Oops, I did nearly all of 4 for you. Oh well.

Iniciar sesión para comentar.

Más respuestas (1)

Mahdi el 30 de Mayo de 2014
What you did produces a vector that starts at 1 and goes up by 5 till it reaches 100 elements. If that was your goal, then it's correct.
But if the question is asking to have a 100 elements which are all equal to 5:


Más información sobre 2-D and 3-D Plots 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!

Translated by