when
x=1
y=x.^2+3 /(x-1)
and when
x=2:100, y=x.^3+55
how do you solve this in matlab using vectorization method

 Respuesta aceptada

Image Analyst
Image Analyst el 18 de Ag. de 2021

0 votos

Try this:
% When x=1, y=x.^2+3 /(x-1) and when x=2:100, y=x.^3+55,
x = 1 : 100;
% In general
y = x .^ 3 + 55;
% Special case for x = 1
y(1) = 1 .^ 2 + 3 ./ (1 - 1); % y will be infinity of course.
% Plot non-infinite results.
plot(x(2:end), y(2:end), 'b-', 'LineWidth', 2);
grid on;
fontSize = 15;
title('y = x .^ 3 + 55', 'FontSize', fontSize, 'Interpreter', 'none');
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);

2 comentarios

Ls
Ls el 18 de Ag. de 2021
Sorry In the case of y(1), the equation is x.^2+3/(x+1)
Image Analyst
Image Analyst el 18 de Ag. de 2021
@Ls, then the line of code would of course be
y(1) = 1 .^ 2 + 3 ./ (1 + 1);

Iniciar sesión para comentar.

Más respuestas (1)

David Hill
David Hill el 17 de Ag. de 2021

0 votos

y=zeros(size(x));
y(x==1)=3;
y(x~=1)=x(x~=1).^3+55;

4 comentarios

Walter Roberson
Walter Roberson el 18 de Ag. de 2021
You overlooked the /(x-1) when x = 1 ...
David Hill
David Hill el 18 de Ag. de 2021
He changed the question.
Image Analyst
Image Analyst el 18 de Ag. de 2021
Yes. Originally it said
"when x=1, y=x.^2+3 /(x-1) and when x=2:100, y=x.^3+55,"
as I captured in the comment in my code. Then in his comment to me (after your and my Answers were posted) he changed it to x.^2+3/(x+1). And I added a comment to update it to the new formula.
Ls
Ls el 18 de Ag. de 2021
Thank you everyone as x-1 does not give proper value i changed the question. Anyway thank you again.

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

Ls
el 17 de Ag. de 2021

Comentada:

Ls
el 18 de Ag. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by