Can someone please help me know what's wrong with my code? because it doesn't show the right graph !

조회 수: 2 (최근 30일)
that's what i have done on Matlab, but I can't get the right graph for the question.
first I created a function :
function [y]=discontinuity(x,a,n,c)
s=length(a);
y=zeros(s,1);
for i=1:s
if x(i)>=a
y(i)=((x(i)-a)^n)/c;
else
y(i)=0;
end
end
end
Then, I created a script
x=0:0.5:360;
y=zeros(length(x),1);
for i=1:length(x)
y(i)= -((100/24)*x(i))^4+(8500/6)*x(i)^3-27.30e6*x(i)+(100/24)*discontinuity(x(i),120,4,29e6*110)-(2000/6)*discontinuity(x(i),180,3,29e6*110)+(9500/6)*discontinuity(x(i),240,3,29e6*110)-(4000/6)*discontinuity(x(i),300,3,29e6*110);
end
plot(x,y)
grid on
xlabel('distance in inches')
ylabel('deflection in inches')

채택된 답변

Stephen23
Stephen23 2017년 3월 23일
편집: Stephen23 2017년 3월 23일
This function:
function y = discontinuity(x,a,n)
y = max(0,x-a).^n;
end
and this script:
x = 0:0.5:360;
y = 1/(29e6 * 110) * (...
- (100/24)*x.^4 + (8500/6)*x.^3 - 27.30e6*x...
+ (100/24)*discontinuity(x,120,4)...
- (2000/6)*discontinuity(x,180,3)...
+ (9500/6)*discontinuity(x,240,3)...
- (4000/6)*discontinuity(x,300,3));
plot(x,y)
grid on
xlabel('distance in inches')
ylabel('deflection in inches')
gives:
MATLAB is a beautiful high-level language. Don't make it slow and ugly by trying to solve every task using loops, as if it were some low-level language like C:
  댓글 수: 2
Rehab Mohamed`
Rehab Mohamed` 2017년 3월 23일
Thanks for your help, but shouldn't the graph be like this one? because my professor said that the graph should look like this one!
Stephen23
Stephen23 2017년 3월 23일
Ask your professor how their beam continues to bend after 300 inches along the beam, even though there is no force on the beam shown in the diagram after that point. Some magic seems to be involved in bending your professor's beam:

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Networks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by