| 5 | 1/1 | 返回列表 |
| 查看: 2057 | 回復(fù): 7 | |||
| 當(dāng)前只顯示滿足指定條件的回帖,點(diǎn)擊這里查看本話題的所有回帖 | |||
longwen8木蟲 (文壇精英)
|
[求助]
微分方程組的四階龍格庫(kù)塔公式求解matlab版 已有1人參與
|
||
|
微分方程組的四階龍格庫(kù)塔公式,求解matlab版的代碼。下面是我的代碼,運(yùn)行不出來(lái)。 function varargout=rungekutta(varargin) clc,clear x0=0;xn=1.0;y0=1;h=0.05;%h為步長(zhǎng) [y,x]=rungekutta4(x0,xn,y0,h); Function z=f(x,y); z=y-2*x/y; function [y,x]=rungekutta4(x0,xn,y0,h) x=x0:h:xn; n=(xn-x0)/h; y1=x; y1(1)=y0; for i=1:n %龍格庫(kù)塔法的算法 K1=f(x(i),y1(i)); K2=f(x(i)+h/2,y1(i)+h/2*K1); K3= f(x(i)+h/2,y1(i)+h/2*K2); K4= f(x(i)+h,y1(i)+h*K3); y1(i+1)=y1(i)+h/6*(K1+2*K2+2*K3+K4); yy1(i)=(1+2*x(i+1)) ^0.5; error(i)=y1(i+1)-yy1(i); yy(i+1)=yy1(i); e(i+1)=error(i); end y=y1; n=(xn-x0)/h; fprintf(‘i x(i) yi數(shù)值解 y(i)真值 誤差\n’); fprintf(‘-------------------------------------------------------------\n’); for i=1:n fprintf(‘%2d %12.4f %14.8f %14.8f %12.8f\n’,i, x(i+1), y(i+1), yy(i+1), error(i)); end plot(x,e,‘r.’);%畫出誤差曲線 xlable(‘x軸’),ylable(‘誤差’); title(‘步長(zhǎng)為0.05時(shí)的誤差曲線’); |
至尊木蟲 (著名寫手)
|
運(yùn)行結(jié)果: i x(i) yi數(shù)值解 y(i)真值 誤差 ------------------------------------------------------------- 1 0.0500 1.04880886 1.04880885 0.00000001 2 0.1000 1.09544514 1.09544512 0.00000002 3 0.1500 1.14017546 1.14017543 0.00000004 4 0.2000 1.18321600 1.18321596 0.00000005 5 0.2500 1.22474493 1.22474487 0.00000006 6 0.3000 1.26491113 1.26491106 0.00000007 7 0.3500 1.30384056 1.30384048 0.00000008 8 0.4000 1.34164088 1.34164079 0.00000009 9 0.4500 1.37840498 1.37840488 0.00000011 10 0.5000 1.41421368 1.41421356 0.00000012 11 0.5500 1.44913781 1.44913767 0.00000014 12 0.6000 1.48323985 1.48323970 0.00000015 13 0.6500 1.51657526 1.51657509 0.00000017 14 0.7000 1.54919353 1.54919334 0.00000019 15 0.7500 1.58113904 1.58113883 0.00000021 16 0.8000 1.61245178 1.61245155 0.00000023 17 0.8500 1.64316793 1.64316767 0.00000026 18 0.9000 1.67332034 1.67332005 0.00000028 19 0.9500 1.70293895 1.70293864 0.00000031 20 1.0000 1.73205115 1.73205081 0.00000034 圖像上傳不上來(lái)。 |

至尊木蟲 (著名寫手)
|
一、幾個(gè)自定義函數(shù)位置錯(cuò)誤。應(yīng)為這樣放置 1、主程序 , function rungekutta() clc,clear x0=0;xn=1.0;y0=1;h=0.05;%h為步長(zhǎng) [y,x]=rungekutta4(x0,xn,y0,h); end 2、 四階龍格庫(kù)塔函數(shù)程序 function [y,x]=rungekutta4(x0,xn,y0,h) 。。。 end 3、z函數(shù)程序 function z=f(x,y); z=y-2*x/y; end 二、xlable(‘x軸’),ylable(‘誤差’);這句代碼中函數(shù)書寫錯(cuò)誤。應(yīng)為 xlabel('x軸'),ylabel('誤差'); 三、修改后運(yùn)行得到如下結(jié)果 |

木蟲 (文壇精英)
木蟲 (文壇精英)
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 293求調(diào)劑 +5 | zjl的號(hào) 2026-03-16 | 6/300 |
|
|---|---|---|---|---|
|
[考研] 267一志愿南京工業(yè)大學(xué)0817化工求調(diào)劑 +6 | SUICHILD 2026-03-12 | 6/300 |
|
|
[考研] 化學(xué)工程321分求調(diào)劑 +10 | 大米飯! 2026-03-15 | 13/650 |
|
|
[考研] 0703化學(xué)調(diào)劑 ,六級(jí)已過(guò),有科研經(jīng)歷 +7 | 曦熙兮 2026-03-15 | 7/350 |
|
|
[考研] 0703一志愿211 285分求調(diào)劑 +5 | ly3471z 2026-03-13 | 5/250 |
|
|
[考研] 070303一志愿西北大學(xué)學(xué)碩310找調(diào)劑 +5 | d如愿上岸 2026-03-12 | 8/400 |
|
|
[考研] 289求調(diào)劑 +4 | 這么名字咋樣 2026-03-14 | 6/300 |
|
|
[考研] 255求調(diào)劑 +3 | 李嘉慧, 2026-03-12 | 4/200 |
|
|
[考研] 328求調(diào)劑 +3 | 5201314Lsy! 2026-03-13 | 6/300 |
|
|
[考研] 材料080500調(diào)劑求收留 +3 | 一顆meteor 2026-03-13 | 3/150 |
|
|
[考研] 招收0805(材料)調(diào)劑 +3 | 18595523086 2026-03-13 | 3/150 |
|
|
[考研] 311求調(diào)劑 +5 | 牛乳糖的卡卡 2026-03-10 | 5/250 |
|
|
[考研] 復(fù)試調(diào)劑 +9 | Copy267 2026-03-10 | 9/450 |
|
|
[考研] 材料與化工求調(diào)劑一志愿 985 總分 295 +8 | dream…… 2026-03-12 | 8/400 |
|
|
[考研] [0860]321分求調(diào)劑,ab區(qū)皆可 +4 | 寶貴熱 2026-03-13 | 4/200 |
|
|
[考研] 工科278分求調(diào)劑 +5 | 周慢熱啊 2026-03-12 | 7/350 |
|
|
[考研] 08食品或輕工求調(diào)劑,本科發(fā)表3篇sci一區(qū)top論文,一志愿南師大食品科學(xué)與工程 +3 | 我是一個(gè)兵, 2026-03-10 | 3/150 |
|
|
[考博] 26讀博 +4 | Rui135246 2026-03-12 | 10/500 |
|
|
[考研] 081200-11408-276學(xué)碩求調(diào)劑 +3 | 崔wj 2026-03-12 | 4/200 |
|
|
[考研] 279求調(diào)劑 +3 | 莫xiao 2026-03-10 | 4/200 |
|