Help plotting function with i?
이전 댓글 표시
Hello, I am trying to plot x and y from x = 0 to x=L. I was having trouble with it, but line y=funct... seems to have fixed it. However, I don't understand this part of the code. Can someone confirm that this is the way to do what I'm trying to do? Thank you
%constants
w0 =2.5 %kN/cm
L = 600 %cm
I = 30000 %cm^4
E = 50000; %kN/cm^2
x =linspace(0,L,100);
y = @(x) w0./(120*E*I*L)*(-5*x^4+6*L^2*x^2-L^4);
yfunc(i) = y(x(i));
plot(x,yfunc)
ylabel('Displacement [cm]')
xlabel('Location [cm]')
title('Max Deflection at x = 531.2241cm')
댓글 수: 5
Kevin Phung
2019년 9월 18일
can you post all of the code?
Rik
2019년 9월 18일
This syntax looks very odd. Unless i is a sym, or yfunc and i are arrays, I don't see how this is a valid syntax.
Raphael Hatami
2019년 9월 18일
dpb
2019년 9월 18일
Agreed...I suppose OP could have defined
i=1:numel(x);
and y is either an array of same or larger size or a function that can accept a vector. The latter, of course, would just be equivalent to writing
yfunc=y(x);
under that condition.
But, is most puzzling and peculiar and without the full code defining the other variables/functions, impossible to truly tell what's going on (or wrong).
Rik
2019년 9월 18일
The i variable is still undefined. If you don't define it, i is the imaginary unit, which would make indexing yfunc impossible. (yfunc is also undefined here)
When you create an example, check if it still runs if you put clearvars at the top.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Common Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!