how to solve equation
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Image Analyst
2021년 8월 18일
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
Image Analyst
2021년 8월 18일
@Ls, then the line of code would of course be
y(1) = 1 .^ 2 + 3 ./ (1 + 1);
추가 답변 (1개)
David Hill
2021년 8월 17일
y=zeros(size(x));
y(x==1)=3;
y(x~=1)=x(x~=1).^3+55;
댓글 수: 4
Image Analyst
2021년 8월 18일
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!