Help me with this error!

조회 수: 4 (최근 30일)
Mobasher Hossain
Mobasher Hossain 2015년 3월 14일
댓글: Mobasher Hossain 2015년 3월 14일
I'm trying to plot x vs y,saving the values in arrays:
clear all;
l = 0.1;
for index = 1:30;
x(index) = (index-1)*0.1;
y(index) = pi*(x.^2 + 1).^2 *l;
end
%PLOT x VERSUS y
plot(x,y);
xlabel('x');
ylabel('pi*((x^2+1)^2)*l');
But I'm getting this error: In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in problem_02 (line 8) y(index) = pi*(x.^2 + 1).^2 *l;

채택된 답변

Roger Stafford
Roger Stafford 2015년 3월 14일
Instead of:
y(index) = pi*(x.^2 + 1).^2 *l;
you should write:
y(index) = pi*(x(index)^2 + 1)^2 *l;
Either that or else you should do:
y = pi*(x.^2 + 1).^2 *l;
after you exit the for-loop.
As it stands you have a scalar on one side of the equation and a vector on the other side in the original
y(index) = pi*(x.^2 + 1).^2 *l;
That is what matlab is unhappy about.
  댓글 수: 1
Mobasher Hossain
Mobasher Hossain 2015년 3월 14일
Thanks Roger.One more question: I was asked to plot the change in revolution as I rotate function (x^2+1) around x axis,using disk method from 0 to 3 with an increment of 0.1.Now,I summed all y= pi*(x^2 +1)^2 * 0.1 for each x from 0 to 30, and stored those values in arrays.The graph that I'm getting is just on the positive y side(I know because my y function is in squares) but how do I get a 'change in volume' graph when I rotate the function around x axis for x 0 to 3?I think the question is asking me for another graph on the negative y axis,isn't it?I'm very confused!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by