声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 932|回复: 0

[综合讨论] 你觉得有挑战性么【打靶法求初值并解微分方程】

[复制链接]
发表于 2009-1-17 17:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
问题见附件图片。

f1.jpg

我编的程序如下:

function  myfun()

cguess=0; % a guess at the value of y'(0)

actualvalue=fzero(@shooting,cguess)
% use ode45 to get correct solution using actualvalue and plot
tspan=[0 1];
y0=[0 actualvalue];
[h,y]=ode45(@concentrationprofile,tspan,y0);
plot(h,y(:,1),'r')
print -deps shootingexampleplot

function f=shooting(c)
% set up as a function, the input (c) is the initial slope y'(0)
% and the output (f) is the difference between the value of y at x=1
% and the number 1 (since y(1)=1 for the correct solution.
% This function is called by MATLABs fzero

% shooting.m
% trying to solve y''+ b1(h) * y' = 0 y(0)=0 y(1)=1
% using y(0)=0 and y’(0)=c
tspan=[0 1];
y0=[0 c];
[t,y]=ode45(@concentrationprofile,tspan,y0);
f=y(length(y),1)-1; % set function value to y(1)-1
return

function f=concentrationprofile(h,y)
% shootingexamplef.m
% the DE y''+ b1(h) * y' = 0 written as a system
q=quad(@(h) sin(h).^0.5,0,h);
s=sin(h)^0.5/q^(1/3);
b1=diff(s,h)./s

f(1)=y(2);
f(2)=-b1*y(2);
f=f(:);
return

当b1取常数时,程序没问题,但是当b1为附件图片所示时,就有问题了。

请教各位高手如何解决?
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 21:25 , Processed in 0.054414 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表