楼主: bostondude
1146 5

[问答] 新手跪求解释???万分感激 [推广有奖]

  • 0关注
  • 0粉丝

已卖:1份资源

大专生

30%

还不是VIP/贵宾

-

威望
0
论坛币
2825 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
325 点
帖子
87
精华
0
在线时间
10 小时
注册时间
2012-1-31
最后登录
2014-5-2

楼主
bostondude 发表于 2012-3-19 11:47:46 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
problem:
用 MATLAB 写一个程序求 f'(0) for f(x) = e^x and
h = 1; 0:1; 0:01 0:001; 0:0001 using the forward di erence formula(前向差分 )
and the central di erence formula (中心差分法 ).  最大的 h直是多少,根据你的matlab程序计算 according
to your computations?

我自己大概写了一下的code,哪位高手帮忙看看,跪求了。。
Problem 1.
%creat user defined function file: euler forward.m
(1) Define function f(x,y)

function [x,y]=euler_forward(f,xinit,yinit,xfinal,n)
% Euler approximation for ODE initial value problem
% Euler forward method

(2)input initial values x0 and y0
% Initialization of x and y as column vectors

x=[xinit zeros(2,n)]; y=[yinit zeros(2,n)];

(3) input step sizes h and number of steps n
% Calculation of h from xinit, xfinal, and n
h=(xfinal-xinit)/n;

(4) Calculation of x and y
for i=1:n
x(i+1)=x(i)+h;
y(i+1)=y(i)+h*f(x(i),y(i));
end
(5) output x and y.



(6) calculation of exact values.

ode45(@xdot,tspan,y0)
%built in functions

f=@(x,y) x./y;
% Calculate exact solution for h=0.01
g=@(x) (e^x);
x[0,100]
xe=[0:0.01:1];
ye=g(xe);

% Calculate exact solution for h=0.1
g=@(x) (e^x);
x[0,100]
xe=[0:0.1:1];

ye=g(xe);

%calculate the exact solution for h=0.001
g=@(x) (e^x);
x[0,100]
xe=[0:0.001: 1];
ye=g(xe);


%calculate the exact solution for h=0.0001
g=@(x) (e^x);
x[0,100]
xe=[0:0.0001: 1];
ye=g(xe);


% Call function
[x4,y4]=ode45(f,[0,1],1);

(8) Estimate errors
error1=['Forward error: ' num2str(-100*(ye(end)-y1(end))/ye(end)) '%'];
==============================================================



















二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:computations Calculation Computation calculate According function central forward problem matlab

沙发
7.wangying 发表于 2012-3-19 11:48:58
看不懂哦
行到水穷处, 坐看云起时。

藤椅
bostondude 发表于 2012-3-19 11:49:58
7.wangying 发表于 2012-3-19 11:48
看不懂哦
是题目看不懂还是我的的程序?

板凳
doubleds 发表于 2012-3-19 11:53:31
你直接用中文写你这段程序想干什么吧,前面那段英文看的人会稀里糊涂的。

报纸
bostondude 发表于 2012-3-19 13:42:31
doubleds 发表于 2012-3-19 11:53
你直接用中文写你这段程序想干什么吧,前面那段英文看的人会稀里糊涂的。
我翻译了,你帮忙看看吧。谢谢了

地板
doubleds 发表于 2012-3-20 15:54:25
你是想要别人看什么?看你的程序对不对吗?

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-16 15:34