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
Kevin Phung 2019년 9월 18일
can you post all of the code?
Rik
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
Raphael Hatami 2019년 9월 18일
woops sorry, I was deleting parts of the code that are not relevant to my question and accidentally deleted the function itself. I've fixed it in the question
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
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개)

태그

질문:

2019년 9월 18일

댓글:

Rik
2019년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by