Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2008-05-14
年龄: 39
帖子: 2
声望力: 0 ![]() |
![]()
我算是新人,接触M不久,下面代码可以精简,大家看看:谢谢。。。。
QQ:275928264,欢迎交流 代码:
%打印T分布表 {19:32 2008-5-13|plp626} function m() %定义主函数 !set/p=%time%<nul>time v=[0.25 0.10 0.05 0.025 0.01 0.005];%设置分位数向量 fprintf('n╲α') for i=1:1:6 fprintf('%10.4f',v(i)) end fprintf('\n') for j=1:1:45 %设置自由度范围1-45 fprintf('%5.1d ',j) for i=1:1:6 fprintf('%10.4f',dt(v(i),j)) if i==6 fprintf('\n') end end end !echo\ %time%>>time !for /f "tokens=*" %a in (time)do timediff %a 0 %对自由度为n,求积分值为v(分为数)时的积分下限值。 function r=dt(v,n) %%//////dt(v,n) h=1; %初始步长 a=0.5; %初值a,然后迭代到我们要求的值。 ta=t(a,n); %初值的积分值:0.5为积分下限。 %%%%这里采用变步长3-4-5逼近法(原创) while abs(ta-v)>0.000001 %设置精度 while ta>v a=a+h;ta=t(a,n); end h=0.3*h;a=a-h; while ta<v a=a-h;ta=t(a,n); end h=0.4*h;a=a+0.5*h; end r=a; %计算自由度为n时[a0,inf]的t积分。对于指定的n,t(a,n)为递减函数。 function r=t(a0,n) %%/////t(a0,n) syms x f=gamma((n+1)/2)/(sqrt(n*pi)*gamma(n/2))*(1+x*x/n)^(-(n+1)/2);%T分布密度函数 f=simplify(f); g=int(f,x,a0,inf); r=numeric(g); 代码:
@echo off||[email protected] :: /* ---------- Timediff --------------- :Timediff [%t1%] [%t2%] [par|0] for %%a in (+%1 +%2 +%3)do if "%%a"=="+" echo 参数缺失!&exit/b setlocal enabledelayedexpansion :timediff_1 set P2=%~1&set "P2=!P2::=!"&set "P2=!P2: =!" set/a P2=%P2:.=%-4000*(%P2:~,4%+60*%P2:~,2%) if not "%3"=="" set P1=!P2!&shift&goto:timediff_1 if !P2! geq !P1! (set/a df=!P2!-!P1!) else set/a df=!P2!-!P1!+8640000 set/a h=df/360000,m=df%%360000/6000,s=df%%6000/100,pt=df%%100 if %pt% leq 9 set pt=0%pt% endlocal&if %2.==0. (echo\%h%:%m%:%s%.%pt%) else set %2=%h%:%m%:%s%.%pt%&goto:eof :: ------------- Timediff ------------- */ ![]() |
![]() |
![]() |
![]() |
#2 |
初级会员
注册日期: 2009-03-05
年龄: 37
帖子: 1
声望力: 0 ![]() |
![]()
matlab中可以用tic/toc命令计时的
|
![]() |
![]() |
![]() |
主题工具 | |
显示模式 | |
|
|
![]() |
||||
主题 | 主题作者 | 版面 | 回复 | 最后发表 |
正弦波变方波 | du2005023029 | MATLAB论坛 | 0 | 2008-06-29 17:02 |
用Matlab如何从一点画一个带有箭头标志的矢量? | hohocrab | MATLAB论坛 | 2 | 2008-06-15 03:29 |
请问:非线性动态电路仿真,如何添加非线性电阻,非线性电容和电感 | berrylolo | MATLAB论坛 | 0 | 2008-05-27 21:12 |
求助,一个有关矩阵的问题 | outteq | MATLAB论坛 | 0 | 2008-05-27 21:01 |