clc;clear all;
l=25;
E=200e9;
I=350e-6;
w=6e3;
for x=linspace(0,l/2,25)
y=(-(w*x)/(384*E*I))*(16*(x^3)-24*l*(x^2)+9*(l^3))
end
for x=linspace(l/2,l,26)
y=(-(w*x)/(384*E*I))*(8*(x^3)-24*l*(x^2)+17*x*(l^2)-(l^3))
end
figure
plot(x,y)

 채택된 답변

Image Analyst
Image Analyst 2014년 11월 26일

0 개 추천

If you're absolutely required to use a for loop, just add an index to y
% Clean up
close all;
clc;
clear all;
l=25;
E=200e9;
I=350e-6;
w=6e3;
x1=linspace(0,l/2,25)
for k = 1 : length(x1)
y1(k)=(-(w*x1(k))/(384*E*I))*(16*(x1(k)^3)-24*l*(x1(k)^2)+9*(l^3))
end
x2=linspace(l/2,l,26)
for k = 1 : length(x2)
y2(k)=(-(w*x2(k))/(384*E*I))*(8*(x2(k)^3)-24*l*(x2(k)^2)+17*x2(k)*(l^2)-(l^3))
end
x = [x1, x2];
y = [y1, y2];
plot(x,y, 'bo-')
grid on;

댓글 수: 2

ernest
ernest 2014년 11월 26일
thank you so much! is it possible if i could get your contact for some other questions?
Image Analyst
Image Analyst 2014년 11월 26일
I'm always here but I don't always have the best ideas so post here and get multiple good ideas you can choose from. You can't get that with a private side discussion with one person. Thanks for accepting though!

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

추가 답변 (1개)

Thorsten
Thorsten 2014년 11월 26일

0 개 추천

Because your y is just a single point. Work on the whole vector and make sure to use .*, ./ and .^ when you want point-wise operation.
l=25;E=200e9;I=350e-6;w=6e3;
x=linspace(0,l/2,25); y=(-(w*x)/(384*E*I)).*(16*(x.^3)-24*l*(x.^2)+9*(l^3)) ;
plot(x, y, 'b')
hold on
x=linspace(l/2,l,26); y=(-(w*x)/(384*E*I)).*(8*(x.^3)-24*l*(x.^2)+17*x*(l^2)-(l^3));
hold on
plot(x, y, 'r')

댓글 수: 1

ernest
ernest 2014년 11월 26일
the question require me to use a loop operation,followed by an array operation. help please!

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2014년 11월 26일

댓글:

2014년 11월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by