matlab 求解 f(x)=x(x+1)(x+2)(x+3)(x+4)...(x+n-2)(x+n-1)(x+n)的导数;
matlab 求解 f(x)=x(x+1)(x+2)(x+3)(x+4)...(x+n-2)(x+n-1)(x+n)的导数;
问题的提出
代码求解
clc; clear; close all;
filename='how10.txt';
syms x; % be careful performance issue.
fileID = fopen(filename, 'w');
str="x";
f=str2sym(str);
fprintf(fileID,'%s\r\n',string(f));
result=diff(f,x);
fprintf(fileID,'%s\r\n',string(result));
ff=matlabFunction(result);
fprintf(fileID,'%d\r\n',1);
fprintf(fileID,'\r\n');
for i = 1:10
newstr="*(x+"+int2str(i)+")";
str=str+newstr;
f=str2sym(str);
fprintf(fileID,'%s\r\n',string(f));
result=diff(f,x);
fprintf(fileID,'%s\r\n',string(result));
ff=matlabFunction(result);
fprintf(fileID,'%f\r\n',ff(0));
fprintf(fileID,'\r\n');
end
代码输出
x 原函数
1 导函数
1
x*(x + 1) 原函数
2*x + 1 导函数
1.000000
x*(x + 1)(x + 2)
(x + 1)(x + 2) + x*(x + 1) + x*(x + 2)
2.000000
x*(x + 1)(x + 2)(x + 3)
x*(x + 1)(x + 2) + x(x + 1)(x + 3) + x(x + 2)(x + 3) + (x + 1)(x + 2)*(x + 3)
6.000000
x*(x + 1)(x + 2)(x + 3)(x + 4)
x(x + 1)(x + 2)(x + 3) + x*(x + 1)(x + 2)(x + 4) + x*(x + 1)(x + 3)(x + 4) + x*(x + 2)(x + 3)(x + 4) + (x + 1)(x + 2)(x + 3)*(x + 4)
24.000000
x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)
x*(x + 1)(x + 2)(x + 3)(x + 4) + x(x + 1)(x + 2)(x + 3)(x + 5) + x(x + 1)(x + 2)(x + 4)(x + 5) + x(x + 1)(x + 3)(x + 4)(x + 5) + x(x + 2)(x + 3)(x + 4)(x + 5) + (x + 1)(x + 2)(x + 3)(x + 4)*(x + 5)
120.000000
x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)
x(x + 1)(x + 2)(x + 3)(x + 4)(x + 5) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 6) + x*(x + 1)(x + 2)(x + 3)(x + 5)(x + 6) + x*(x + 1)(x + 2)(x + 4)(x + 5)(x + 6) + x*(x + 1)(x + 3)(x + 4)(x + 5)(x + 6) + x*(x + 2)(x + 3)(x + 4)(x + 5)(x + 6) + (x + 1)(x + 2)(x + 3)(x + 4)(x + 5)*(x + 6)
720.000000
x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)
(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6) + x(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 7) + x(x + 1)(x + 2)(x + 3)(x + 4)(x + 6)(x + 7) + x(x + 1)(x + 2)(x + 3)(x + 5)(x + 6)(x + 7) + x(x + 1)(x + 2)(x + 4)(x + 5)(x + 6)(x + 7) + x(x + 1)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7) + x(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)*(x + 7)
5040.000000
x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)
(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 8) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 7)(x + 8) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 6)(x + 7)(x + 8) + x*(x + 1)(x + 2)(x + 3)(x + 5)(x + 6)(x + 7)(x + 8) + x*(x + 1)(x + 2)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8) + x*(x + 1)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8) + x*(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)
40320.000000
x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9)
x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8) + x(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 9) + x(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 8)(x + 9) + x(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 7)(x + 8)(x + 9) + x(x + 1)(x + 2)(x + 3)(x + 4)(x + 6)(x + 7)(x + 8)(x + 9) + x(x + 1)(x + 2)(x + 3)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9) + x(x + 1)(x + 2)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9) + x(x + 1)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9) + x(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9) + (x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)*(x + 9)
362880.000000
x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9)(x + 10)
x(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 10) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 9)(x + 10) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 8)(x + 9)(x + 10) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 7)(x + 8)(x + 9)(x + 10) + x*(x + 1)(x + 2)(x + 3)(x + 4)(x + 6)(x + 7)(x + 8)(x + 9)(x + 10) + x*(x + 1)(x + 2)(x + 3)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9)(x + 10) + x*(x + 1)(x + 2)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9)(x + 10) + x*(x + 1)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9)(x + 10) + x*(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9)(x + 10) + (x + 1)(x + 2)(x + 3)(x + 4)(x + 5)(x + 6)(x + 7)(x + 8)(x + 9)*(x + 10)
3628800.000000
分析代码结果
可以看出来
结果为
matlab 求解 f(x)=x(x+1)(x+2)(x+3)(x+4)...(x+n-2)(x+n-1)(x+n)的导数;的更多相关文章
- matlab 求解线性规划问题
线性规划 LP(Linear programming,线性规划)是一种优化方法,在优化问题中目标函数和约束函数均为向量变量的线性函数,LP问题可描述为: minf(x):待最小化的目标函数(如果问题本 ...
- fslove - Matlab求解多元多次方程组
fslove - Matlab求解多元多次方程组 简介: 之前看到网上的一些资料良莠不齐,各种转载之类的,根本无法解决实际问题,所以我打算把自己的学到的总结一下,以实例出发讲解fsolve. 示例如下 ...
- 用Matlab求解微分方程
用Matlab求解微分方程 解微分方程有两种解,一种是解析解,一种是数值解,这两种分别对应不同的解法 解析解 利用dsolve函数进行求解 syms x; s = dsolve('eq1,eq2,.. ...
- MATLAB求解代数方程、微分方程的一些常用指令
MATLAB版本:R2015b 1.求解符号矩阵的行列式.逆.特征值.特征向量 A = sym('[a11, a12; a21, a22]');deltaA = det(A)invA = inv(A) ...
- MATLAB求解二重积分案例
凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 定积分解决的是一维连续量求和的问题,而解决多维连续量的求和问题就要用到重积分了.重积分是建立在定积分的基础上的 ...
- yalmip + lpsolve + matlab 求解混合整数线性规划问题(MIP/MILP)
最近建立了一个网络流模型,是一个混合整数线性规划问题(模型中既有连续变量,又有整型变量).当要求解此模型的时候,发现matlab优化工具箱竟没有自带的可以求解这类问题的算法(只有bintprog求解器 ...
- MATLAB求解常微分方程:ode45函数与dsolve函数
ode45函数无法求出解析解,dsolve可以求出解析解(若有),但是速度较慢. 1. ode45函数 ①求一阶常微分方程的初值问题 [t,y] = ode45(@(t,y)y-2*t/y, ...
- MATLAB求解非线性方程组
matlab中有专门的solve函数来解决方程组的(a-x)^2+(b-y)^2=e^2(C-x)^2+(D-y)^2=v^2已知a,b,c,d,e,v 值求解 X,Y 请问用 matlab 如何写, ...
- matlab 求解 Ax=B 时所用算法
x = A\B; x = mldivide(A, B); matlab 在这里的求解与严格的数学意义是不同的, 如果 A 接近奇异,matlab 仍会给出合理的结果,但也会提示警告信息: 如果 A 为 ...
- [Matlab]求解线性方程组
转自:http://silencethinking.blog.163.com/blog/static/911490562008928105813169/ AX=B或XA=B在MATLAB中,求解线性方 ...
随机推荐
- linux添加分辨率
由于屏幕分辨率是1920X1080,但是虚拟机中的centos的分辨率设置中没有这个值,因此需要添加一个.在终端中输入如下命令:1.cvt 1920 1080得到: # 1920x1080 59.96 ...
- HIVE- 各年逐月累加函数
select year_flag,month_flag,field,SUM(field) OVER (PARTITION BY year_flag ORDER BY month_flag)from t ...
- Excel条件格式的应用
一.突出单元格规则 大于/小于/等于/包含/发生日期/重复值 发生日期(自定义)通常通过辅助单元格进行:选中单元格区域,条件格式-新建规则-选择规则类型(使用公式确定要设置的单元格),设置内容如下 二 ...
- C#封装FluentValidation
FluentValidation是一个非常强大的用于构建强类型验证规则的 .NET 框架,帮程序员解决了繁琐的校验问题,用起来非常爽,但我还是遇到了一件非常不爽的事情,如下代码所示: public c ...
- springboot gradle 集成流程引擎activiti
buildscript { repositories { maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } } dep ...
- Day22:数据库导入&分工&准备科研训练
今日完成的任务: 1.与组员共同排查jar包中的问题,发现是由于未导入数据库. 网上查询后在MySQL workbench中完成了导入导出(图中user数据库). 2.完成实验报告分工,我负责结论部分 ...
- hive在执行简单的insert命令也会卡在kill command
终于解决了 我的配置有点问题,但在每次进入hive后,执行一遍 set hive.exec.mode.local.auto=true; 就可以用了 终于,困扰我三四天的问题解决了
- raise EOFError("Compressed file ended before the " EOFError: Compressed file ended before the end-of-stream marker was reached
参考: EOFError: Compressed file ended before the end-of-stream marker was reached解决办法(在Windows下查看已下载的M ...
- uniapp打包app出现HTML5+ Runtime
在manifest.json->源码视图的 "app-plus"下面添加: "app-plus" : { "compatible" : ...
- COOP/COHP(上)-PROOUT
晶体轨道重叠布居 COOP(crystal orbital overlap population)的一个更为直观的名称是 重叠布居权重的态密度 (overlap population-weighted ...