Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Does anyone know how to fix this?

조회 수: 1 (최근 30일)
Caylan Stark
Caylan Stark 2019년 12월 4일
마감: MATLAB Answer Bot 2021년 8월 20일
I'm using forward differencing to estimate a differential equation, but my estimation isn't accounting for my boundary value y(10)=0
%cleanup
clc
clear
clf
%variables and setup
q = -0.6
EI = 1900
L = 10
%Analytical Solution and plot
f = @(x) (q*x.*(L.^3-2*L*x.^2+x.^3))/(24*EI)
x_exact = linspace(0,L)
y_exact = f(x_exact)
figure(1)
hold on
plot(x_exact,y_exact)
%Numerical Solution and Plot
dx = input('Input delta x value: ')
N = (L/dx)+1
y(1) = 0
y(L+1) = 0
y(10) = 0
x(1) = 0
x(2) = dx
C = (q*dx^2)/(2*EI)
for (i=2:N-1)
x(i+1) = x(i) + dx
y(i+1) = C*(x(i)*(x(i)-L))+2*y(i)-y(i-1)
i = i+1
end
plot(x,y)
title('Deflection vs. Position')
xlabel('X')
ylabel('Deflection')
legend('Exact Solution', 'Forward Differencing','Location','NorthWest')
  댓글 수: 1
Ridwan Alam
Ridwan Alam 2019년 12월 4일
Can you please share the code using the 'code editor'?
Capture.PNG

답변 (1개)

Ridwan Alam
Ridwan Alam 2019년 12월 4일
y(10) referes to the 10th element of the array y; not necessarily the value of y when x=10 or the last array element. to assign the last element of y, you can use the length of y (N) to initialize: y(N)=0 or y(length(y_exact))=0;
is your increment of i [i = i+1] intentional inside the for loop? also, the for loop runs upto i=N-1, then y(i+1)=y(N)=whatever is calculated by your equation and it overwrites your initial assignment.
a forward differencing doesn't use the end boundary value in estimating.

이 질문은 마감되었습니다.

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by