声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3191|回复: 12

[编程技巧] 请教三角函数所有解的问题

[复制链接]
发表于 2006-7-20 20:22 | 显示全部楼层 |阅读模式

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

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

x
现在有这样一个三角函数:
T21=-sin(s/delta)*cos(s*delta)+sin(s*delta)*cos(s/delta)/delta^2
T21是s的函数.当把其中的参数delta设为1.5时,用solve得到如下解:
ans =

  18.8496         
        0         
   7.3959         
  -7.3959         
  11.4537         
-11.4537         
   3.3698         
  -3.3698         
  15.4798         
-15.4798         
   4.8744 - 0.7749i
  -4.8744 + 0.7749i
  13.9752 + 0.7749i
-13.9752 - 0.7749i
   9.4248 - 0.8593i
  -9.4248 + 0.8593i
   9.4248 + 0.8593i
  -9.4248 - 0.8593i
   4.8744 + 0.7749i
  -4.8744 - 0.7749i
  13.9752 - 0.7749i
-13.9752 + 0.7749i
我们知道,T21的所有根远远不止这些.根据T21的曲线图,该函数"大致"具有拍频现象,
但在具体的每一个小周期内,函数并不光滑,也不规则,这也即是我强调的"大致"的原因.
在这种情况下,如何才能得到更多的解?

同时,如果将参数delta设为1.501时,用同样的方法,solve只能得到这样一个结果:
ans =

     0
这个差异似乎太大了.T21并没有什么特殊性,为什么很小的参数改变量却能导致很大的结
果差异?请教这是solve的问题还是函数本身的问题?

谢谢!
BOW//

本帖被以下淘专辑推荐:

回复
分享到:

使用道具 举报

发表于 2006-7-21 08:52 | 显示全部楼层
我也想搞懂这个问题,能不能给s设个范围,解出某个范围内有值。不然因为三角函数的周期性,那解不是有无穷多个了?
我用最简单的一个sin(t)=0.5试了一下,也只有一个解。
用sin(t)=1.5试了一下,也出来一个复数解,按道理,它是没有解的吧?这里的复数是什么意思呢?
 楼主| 发表于 2006-7-21 11:15 | 显示全部楼层
原帖由 siyanger 于 2006-7-21 08:52 发表
我也想搞懂这个问题,能不能给s设个范围,解出某个范围内有值。不然因为三角函数的周期性,那解不是有无穷多个了?
我用最简单的一个sin(t)=0.5试了一下,也只有一个解。
用sin(t)=1.5试了一下,也出来一个复数 ...


如果是复数的话,就可以表示成双曲函数,这个是允许的.

但关键是如何求出所有的解.也许是solve的功能太有限,不知道除了solve,还有什么命令可以求出所有的实根和复根.
发表于 2006-7-21 15:03 | 显示全部楼层
你是怎么求的啊?用符号求解的吗?
发表于 2006-7-21 15:57 | 显示全部楼层
理论上fsolve可以求解所有的实数解,复数解貌似没有什么官方命令可以实现。
  1. function SolveTriFun
  2. x0=0;
  3. delta=1.5;
  4. str=['-sin(s/',num2str(delta),').*cos(s*',num2str(delta),')+sin(s*',num2str(delta),').*cos(s/',num2str(delta),')/',num2str(delta),'^2'];
  5. T21=inline(str,'s');
  6. for i=1:5:300
  7.     Results(i)=fsolve(T21,x0);
  8.     x0=i;
  9. end
  10. Results1=unique(Results);
  11. save Results.mat
  12. plot(Results1)
复制代码
 楼主| 发表于 2006-7-21 17:33 | 显示全部楼层
原帖由 bainhome 于 2006-7-21 15:57 发表
理论上fsolve可以求解所有的实数解,复数解貌似没有什么官方命令可以实现。
function SolveTriFun
x0=0;
delta=1.5;
str=;
T21=inline(str,'s');
for i=1:5:300
    Results(i)=fsolve(T21,x0);
    x0=i ...


非常感谢您提供的代码,运行后除了能看到以下的输出和一张图外,看不到解.敢问要看到解的话,是不是还有其他的操作?谢谢.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
Optimization terminated: first-order optimality is less than options.TolFun.
 楼主| 发表于 2006-7-21 17:34 | 显示全部楼层
原帖由 siyanger 于 2006-7-21 15:03 发表
你是怎么求的啊?用符号求解的吗?


我用的是如下的代码:
function [s0]=ST21(delta)

% mu=0.5;
% delta=sqrt(1+0.5*mu+sqrt((1+0.5*mu)^2-1));
delta=1.501;
syms s;
T21=-sin(s/delta)*cos(s*delta)+sin(s*delta)*cos(s/delta)/delta^2;

[s0]=solve(T21);
s0=eval(s0);
发表于 2006-7-21 19:14 | 显示全部楼层
我在书上看到这样一个例子:
qcc=inline('cos(t).*cosh(t)-1','t');
options=optimset('display','off');
% plot(t,qcc(t))
%axis([0 20 -10 10])
xo=[3 5];
for n=1:5
    q(n)=fzero(qcc,xo,options);
    xo=[1.05*q(n) q(n)+4];
end

disp([num2str(q)])

他是这样做的,画出这个函数的图形,看一下解的大概位置,然后求出大周期内的解。
我觉得 这样也有道理。我准备试一下,我的三角函数比你的简单:cos(t)+sin(t)+cos(2*t)+sin(2*t)-0.2
但因为是迭代过程中要用到的,所以更不好处理。
你可以试一下这个方法。
发表于 2006-7-21 19:42 | 显示全部楼层
command windows中运行:
load Results.mat
在workspace中看,其中有个别几个不是解
发表于 2006-7-21 21:07 | 显示全部楼层
原帖由 bainhome 于 2006-7-21 15:57 发表
理论上fsolve可以求解所有的实数解,复数解貌似没有什么官方命令可以实现。
function SolveTriFun
x0=0;
delta=1.5;
str=;
T21=inline(str,'s');
for i=1:5:300
    Results(i)=fsolve(T21,x0);
    x0=i ...


对于sin(t)+cos(t)+sin(2t)+cos(2t)这样的方程,这里的300可以设为2*pi,当做一个周期也可以吧? 谢谢你!
 楼主| 发表于 2006-7-21 22:09 | 显示全部楼层
原帖由 bainhome 于 2006-7-21 19:42 发表
command windows中运行:
load Results.mat
在workspace中看,其中有个别几个不是解




其中您说的个别不是解的问题,请教是怎么会产生的?
另外,我把得到的结果和1楼的结果对照了一下,除了多出解外,还少了解,难道说solve也会得到多余的解?还是两种命令都存在缺陷?

由于我想得到一定量的实根和复根,请教solve是否有初值一说?

谢谢指点!

[ 本帖最后由 shuitumu 于 2006-7-21 23:09 编辑 ]
发表于 2006-7-22 01:28 | 显示全部楼层
solve的是maple的符号计算引擎,使用solve基本是对maple的外部调用,maple本身应该就没有初值参数的设定。基本原理不详。
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
这句话说得应该比较明白了,函数值收敛条件没有达到,原因是初值选择不好,至于少解,随便调一下循环次数即可,fsolve应可以得到所有实数解。复根不行。
另外在MAPLE中的solve也无法求解所有根
 楼主| 发表于 2006-7-22 12:57 | 显示全部楼层
原帖由 bainhome 于 2006-7-22 01:28 发表
solve的是maple的符号计算引擎,使用solve基本是对maple的外部调用,maple本身应该就没有初值参数的设定。基本原理不详。
Sum of squares of the function values is > sqrt(options.TolFun).
Try again wit ...


知道了.谢谢!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-11-20 04:43 , Processed in 0.056379 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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