Info
此问题已关闭。 请重新打开它进行编辑或回答。
Does anyone know how to fix this?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!