How to plot this code?

조회 수: 6 (최근 30일)
hosi
hosi 2023년 7월 10일
댓글: hosi 2023년 7월 10일
Hey guys I've been trying to learn mathlab and I ended up writing this code the code below:
clc
close all;
clear
L=input("L= ");
Delta_a=input("Delta a= ");
W=input("W= ");
E=input("Modulus Yang= ");
I=input("I= ");
EI=E*I;
N=L/Delta_a;
n=0;
while n<N
a=n*Delta_a;
y1=(-W/(24*EI))*((a^4)-(4*L*(a^3)+(6*(L^2)*(a^2))));
Rd=((3*EI)/(L^3))*(y1);
tb1=(-W*(L^3))/(6*EI);
tb2=(Rd*(a^2))/(2*EI);
yb1=(-W*(L^4))/(8*EI);
yb2=((Rd*(a^3))/(3*EI))+((L-a)*tb2);
thetaB=tb1+tb2;
yB=yb1+yb2;
n=n+1;
if(n>N) end
fprintf('n= #%d\n', n);
fprintf('Reaction D= #%d\n', Rd);
fprintf('Shib= #%d\n', thetaB);
fprintf('Khamesh= #%d\n', yB);
end
So here is my question:
How can I plot yB on diffrent values of a?
My guess is to turn it into a matrix but I have no idea about how to that.

채택된 답변

N A POORNA CHANDRA
N A POORNA CHANDRA 2023년 7월 10일
hi hosi , here is the code to plot yB on diffrent values of a?
i have assumed few hard coded values instead of taking them as input
clc
close all;
clear
L = 10; % Length (assumed value)
Delta_a = 0.5; % Delta a (assumed value)
W = 100; % W (assumed value)
E = 2e11; % Modulus of elasticity (assumed value)
I = 0.001; % I (assumed value)
EI = E * I;
N = L / Delta_a;
n = 0;
a_values = [];
yB_values = [];
while n < N
a = n * Delta_a;
y1 = (-W / (24 * EI)) * (a^4 - 4 * L * (a^3) + 6 * (L^2) * (a^2));
Rd = (3 * EI / (L^3)) * y1;
tb1 = (-W * (L^3)) / (6 * EI);
tb2 = (Rd * (a^2)) / (2 * EI);
yb1 = (-W * (L^4)) / (8 * EI);
yb2 = ((Rd * (a^3)) / (3 * EI)) + ((L - a) * tb2);
thetaB = tb1 + tb2;
yB = yb1 + yb2;
a_values = [a_values, a];
yB_values = [yB_values, yB];
n = n + 1;
end
plot(a_values, yB_values)
xlabel('a')
ylabel('yB')
title('Plot of yB against a')
grid on
  댓글 수: 1
hosi
hosi 2023년 7월 10일
Your an angel dude! thanks a lot! <3

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by