标签:
tfti模块串行口jb杂谈 |
分类: 单片机 |
标签:
堆栈杂谈 |
分类: 单片机 |
标签:
指令教育 |
分类: matlab |
更多有关单片机、matlab的文章:链接地址
1、fminbnd函数
x = fminbnd(fun,x1,x2)
x = fminbnd(fun,x1,x2,options)
说明:x = fminbnd(fun,x1,x2) returns a value x that is a local
minimizer of the function that is described in fun in the interval
x1 < x < x2. fun is a function handle.
f = @(x)x.^3-2*x-5; x = fminbnd |
标签:
程序教育 |
分类: 数值分析 |
!Simpson method for integral
module INTEGRAL
implicit none
contains
real function integ(a,b,m) !subfunction
implicit none
real a,b,l
integer m,i
real datas(m)
real,external::func
if(mod(m,2)==0) then
write(*,*) 'm is an even number,please enter an odd number'
end if
forall(i=1:m) !build an array
datas(i)=a+(i-1)*l/(m-1)
end forall
l=b-a
integ=0
!!!!!!!!enter to the key code segment
integ=datas(1)+datas(m)
do i=2,m-1
if(mod(i,2)==0) then
integ=integ+4.0*f(datas(i))
else
integ=integ+2.0*f(dat
标签:
程序教育 |
分类: 数值分析 |
function s=simpson_integral(a,b,m)
%input: a--下限
% b--上限
% m--步数
h=(b-a)/(2*m);
s1=0;
s2=0;
for i=1:(m-1)
x=a+2*i*h;
s1=s1+f(@f,x);
end
for i=1:m
x=a+(2*i-1)*h;
s2=s2+f(@f,x);
end
s=h/3*(f(@f,a)+f(@f,b)+2*s1+4*s2);
标签:
程序教育 |
分类: 数值分析 |
function s=Self_Adaptive_integral(a,b,tol,M)
%input: a--下限
% b--下限
% tol--the tolerance(容差)
% m--初始设置的步数
h=(b-a)/M;%步距
s=0;
for i=1:M
x=a+(i-1)*h;
y=a+i*h;
to=abs(simpson_integral(x,y,2)+simpson_integral(x,y,1))/10;
j=1;
while(to>=tol) %循环直到to<tol为止
j=j+1;
to=(abs(simpson_integral(x,y,2^j)-simpson_integral(x,y,1)))/10;
&nbs
标签:
常识教育 |
分类: 光学 |
标签:
小知识教育 |
分类: matlab |
首先必须明白它们的功能:syms是定义符号变量 ;sym则是将字符或者数字转换为字符。
y=sym(’x');和syms x;y=x;的功能一样。
另外sym x和syms x有很大的区别: sym x是将字符‘x’转换为字符,而syms x则是定义符号变量x。
在command window中输入:
>> sym x
ans =
x
>> syms x
>> whos
Name Size Bytes Class Attributes
ans 1×1 58 sym
x 1×1 58 sym
可以看出他们的巨大差异!