数值集成在Matlab中。为什么增加的分割导致输出不准确?

时间:2016-11-26 21:57:41

标签: matlab numerical-methods numerical-integration

我目前正在研究Matlab中的一个问题,我给它一个分布式加载梁,然后数值积分(使用复合梯形法则)来找到剪切力和弯矩。从那里我找到最大力矩值和发生这种情况的位置。然后我区分两次再次找到剪切力和分布载荷。

我正在使用分析集成的函数来检查并确保正确计算每个数值积分和微分。我的问题是,当我只使用13个点来执行计算时(x = 0:12;),我的值与我从分析值得到的结果一样接近。 (这个数字来自12英尺的横梁,每个横截面是1英尺)。当我增加分割数量以提高数值积分的准确性时,值会远离分析值。我想弄清楚究竟是什么造成了这种情况,但迄今为止都没有成功。

我的代码:

clear; clc;
% n=100;
% x = linspace(0,12,n+1);            %dx (100 divisions)
x=0:12;                              %dx (12 divisions)
w = 12.5.*x;                         %distributed load

%//Integrated Shear
V(1)=300;
for i = 2: length(w)
    weight = [.5   ones(1,i-2)   .5];
    V(i)=300-sum(weight.*w(1:i));
end
figure(1); clf;
plot(x,V,'--'); 
legend('Numerical Shear');
xlabel('Position (ft)'); ylabel('Shear Force (lb)');

%//Integrated Moment
Mactual = 300.*x - ((25/12).*(x.^3));         %analytically integrated M
M(1)=0;
for i = 2: length(V)
    weight = [.5   ones(1,i-2)   .5];
    M(i)=sum(weight.*V(1:i));
end
figure(2); clf;
plot(x,M,'--'); hold on;
plot(x,Mactual); hold off;
legend('Numerical Moment' , 'Analytical Moment');
xlabel('Position (ft)'); ylabel('Bending Moment (lbf)');

%//Max Moment and Position at Max Moment
[maxMValue, indexAtMaxM] = max(M);
xValueAtMaxMValue = x(indexAtMaxM(1));
dispM = [ 'Maximum bending moment: ' , num2str(maxMValue) , ' lbf'];
disp(dispM);
dispX = [ 'Position at maximum bending moment: ' , num2str(xValueAtMaxMValue) , ' ft' ];
disp(dispX)

%//Derived Shear
dM(1)=300;
for i = 1:length(x)-1        
    dM(i+1) = (M(i+1)-M(i));     
end
figure(3); clf;
plot(x,dM,'--'); hold on;
Vactual = 300 - 6.25.*(x.^2);         %analytically integrated shear
plot(x,Vactual); hold off;
legend('Numerical Shear' , 'Analytical Shear');
xlabel('Position (ft)'); ylabel('Shear Force (lb)');

%//Derived Load
dV(1)=0;
for i = 1:length(x)-1        
    dV(i+1) = -(V(i+1)-V(i));     
end
figure(4); clf;
plot(x,dV,'--'); hold on;
plot (x,w); hold off;
legend('Numerical Load' , 'Analytical Load');
xlabel('Position (ft)'); ylabel('Distributed Load (lb/ft)');

在上面的代码中,第2行和第3行被注释掉,以显示仅有12个分区的输出。如果取消注释这两行并注释掉第4行,则输出显示100个分区的值。

快速注意:分析值是针对积分力矩,导出剪切和导出的分布载荷作为比较绘制的。将分析值(Mactual和Vactual)视为正确的输出值。

任何可以帮助我找到解决这个问题的方法的输入都将不胜感激。

1 个答案:

答案 0 :(得分:0)

要获得正确的积分值,如果(defproject chess "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :dependencies [[bouncer "1.0.0"] [buddy "1.1.0"] [compojure "1.5.1"] [com.google.cloud/google-cloud-datastore "0.7.0"] [cprop "0.1.9"] [luminus-immutant "0.2.2"] [luminus-nrepl "0.1.4"] [markdown-clj "0.9.90"] [metosin/compojure-api "1.1.9"] [metosin/ring-http-response "0.8.0"] [mount "0.1.10"] [org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.9.293" :scope "provided"] [org.clojure/tools.cli "0.3.5"] [org.clojure/tools.logging "0.3.1"] [org.webjars.bower/tether "1.3.7"] [org.webjars/bootstrap "4.0.0-alpha.5"] [org.webjars/font-awesome "4.6.3"] [org.webjars/webjars-locator-jboss-vfs "0.1.0"] [reagent "0.5.1"] [ring-middleware-format "0.7.0"] [ring-webjars "0.1.1"] [ring/ring-defaults "0.2.1"] [selmer "1.10.0"]] :min-lein-version "2.0.0" :jvm-opts ["-server" "-Dconf=.lein-env"] :source-paths ["src/clj" "src/cljc"] :java-source-paths ["src/java"] :resource-paths ["resources" "target/cljsbuild"] :target-path "target/%s/" :main chess.core :plugins [[lein-cprop "1.0.1"] [lein-cljsbuild "1.1.4"] [lein-immutant "2.1.0"]] :clean-targets ^{:protect false} [:target-path [:cljsbuild :builds :app :compiler :output-dir] [:cljsbuild :builds :app :compiler :output-to]] :figwheel {:http-server-root "public" :nrepl-port 7002 :css-dirs ["resources/public/css"] :nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]} :profiles {:uberjar {:omit-source true :prep-tasks ["compile" ["cljsbuild" "once" "min"]] :cljsbuild {:builds {:min {:source-paths ["src/cljc" "src/cljs" "env/prod/cljs"] :compiler {:output-to "target/cljsbuild/public/js/app.js" :externs ["react/externs/react.js"] :optimizations :advanced :pretty-print false :closure-warnings {:externs-validation :off :non-standard-jsdoc :off}}}}} :aot :all :uberjar-name "chess.jar" :source-paths ["env/prod/clj"] :resource-paths ["env/prod/resources"]} :dev [:project/dev :profiles/dev] :test [:project/dev :project/test :profiles/test] :project/dev {:dependencies [[prone "1.1.2"] [ring/ring-mock "0.3.0"] [ring/ring-devel "1.5.0"] [pjstadig/humane-test-output "0.8.1"] [binaryage/devtools "0.8.2"] [com.cemerick/piggieback "0.2.2-SNAPSHOT"] [doo "0.1.7"] [figwheel-sidecar "0.5.8"]] :plugins [[com.jakemccrary/lein-test-refresh "0.14.0"] [lein-doo "0.1.7"] [lein-figwheel "0.5.8"] [org.clojure/clojurescript "1.9.293"]] :cljsbuild {:builds {:app {:source-paths ["src/cljs" "src/cljc" "env/dev/cljs"] :compiler {:main "chess.app" :asset-path "/js/out" :output-to "target/cljsbuild/public/js/app.js" :output-dir "target/cljsbuild/public/js/out" :source-map true :optimizations :none :pretty-print true}}}} :doo {:build "test"} :source-paths ["env/dev/clj" "test/clj"] :resource-paths ["env/dev/resources"] :repl-options {:init-ns user} :injections [(require 'pjstadig.humane-test-output) (pjstadig.humane-test-output/activate!)]} :project/test {:resource-paths ["env/test/resources"] :cljsbuild {:builds {:test {:source-paths ["src/cljc" "src/cljs" "test/cljs"] :compiler {:output-to "target/test.js" :main "chess.doo-runner" :optimizations :whitespace :pretty-print true}}}} } :profiles/dev {} :profiles/test {}}) dx=12/n不同,则需要将函数值总和乘以dx=x(2)-x(1)或相同n

(11/28)您还可以简化梯形积分循环

12
因此,避免重建权重和计算每个步骤中的和。这将算法的这部分从O(n ^ 2)减少到O(n)。