make函数matlab,在MATLAB中编写没有硬编码的符号函数(Making symbolic functions without hard-coding in MATLAB)...

在MATLAB中编写没有硬编码的符号函数(Making symbolic functions without hard-coding in MATLAB)

我想做符号函数theta1(t) , theta2(t) , theta3(t) ,... thetaN(t) ,其中N是我可以在MATLAB中定义的一些参数。 我知道我可以用sym('theta',[1 N])来获得[theta1, theta2, theta3,..., thetaN] 。 然而,我怎样才能用theta做同样的事情呢? 硬编码的方式就像syms theta1(t) theta2(t) theta3(t) ... thetaN(t) ,但我想做这个一般。

我不想在这里直接使用sym命令,因为“支持字符向量不是有效的变量名称并且没有定义一个数字将在未来版本中被删除”,这意味着像sym('theta1(t)')在将来的版本中无效。

有什么建议么?

I want to make symbolic functions theta1(t), theta2(t), theta3(t),...,thetaN(t) where N is some parameter I can define in MATLAB. I know that I can use something like sym('theta',[1 N]) to get [theta1, theta2, theta3,..., thetaN]. However, how can I do the same thing with theta being a function of t? The way to hard-code it would be like syms theta1(t) theta2(t) theta3(t) ... thetaN(t), but I want to make this general.

I do not want to directly use the sym command here because "support of character vectors that are not valid variable names and do not define a number will be removed in a future release", meaning something like sym('theta1(t)') would not be valid in future releases.

Any suggestions?

原文:https://stackoverflow.com/questions/43164824

2020-01-14 01:54

满意答案

它的部分出来了。 我可以做如下的事情

for i = 1:N

syms(strcat('theta',num2str(i),'(t)'))

end

但是,如果我想分配一个包含所有符号表达式的变量,我仍然卡住。 如果我尝试

for i = 1:N

my_array(i) = syms(strcat('theta',num2str(i),'(t)'))

end

我Error using syms (line 133). Using input and output arguments simultaneously is not supported.得到Error using syms (line 133). Using input and output arguments simultaneously is not supported. Error using syms (line 133). Using input and output arguments simultaneously is not supported. 它适用于如果我使用sym而不是syms ,但这会导致我在原始帖子中提到的警告。

Figured part of it out. I could do something like the following

for i = 1:N

syms(strcat('theta',num2str(i),'(t)'))

end

However, if I want to assign a variable that contains all the symbolic expressions I'm still stuck. If I try

for i = 1:N

my_array(i) = syms(strcat('theta',num2str(i),'(t)'))

end

I get Error using syms (line 133). Using input and output arguments simultaneously is not supported. It works if I use sym instead of syms, but this leads to the warning I mentioned in my original post.

2017-04-02

相关问答

从你的问题来看,在我看来,你想要/需要的不是一个真正的符号函数,而是一个函数句柄。 如果是这种情况,我会选择类似下面的代码。 为“丑陋的事物”道歉,比如while 1 ,......但它让例子简短: A = {};

while 1

str = input('Enter a function of t (simply press return to exit):','s');

if isempty(str), break; end

A{end+1} = str2func(['...

事实证明这很容易(在我花了20分钟使它变得非常困难之后)。 >> y = sym('t*x(t)')

>> y_dot = diff(y,t)

y_dot =

t*diff(x(t), t) + x(t)

如果需要,您还可以定义一些中间体 >> f = sym('x(t)');

>> y = t*f;

>> diff(y,'t')

ans =

t*diff(x(t), t) + x(t)

我还发现了mupad命令,值得一试。 在mupad窗口中,键入y(x) := t*x(t)和diff(y(...

它的部分出来了。 我可以做如下的事情 for i = 1:N

syms(strcat('theta',num2str(i),'(t)'))

end

但是,如果我想分配一个包含所有符号表达式的变量,我仍然卡住。 如果我尝试 for i = 1:N

my_array(i) = syms(strcat('theta',num2str(i),'(t)'))

end

我Error using syms (line 133). Using input and output argument...

你也可以使用eval()来评估你通过subs()函数得到的函数 f=sin(x);

a=eval(subs(f,1));

disp(a);

a =

0.8415

You can use also use eval() to evaluate the function that you get by subs() function f=sin(x);

a=eval(subs(f,1));

disp(a);

a =

0.8415

这看起来非常好用,并且非常容易扩展。 我仅将H_0重新定义为H_1作为示例。 syms z

H_1(z) = 1+z^-1;

H_0(z) = 1+0*z^-1;

G_0=@(Ha,z) Ha(z^(4))*Ha(z^(2))*Ha(z);

G_1=@(Ha,Hb,z) Hb(z^(4))*Ha(z^(2))*Ha(z);

G_0(H_0,z)

G_1(H_0,H_1,z)

H_0=@(z) H_1(z);

G_0(H_0,z)

G_1(H_0,H_1,z)

This seems to...

这是对您的问题的另一个答案,假设我们必须使用符号数学工具箱。 首先,正常创建您的公式: syms x

f = formula([x, x^2, x^3);

然后,您可以使用subs将x的值替换为您想要的值。 subs有这样的语法: out = subs(f, val);

val可以是您希望替换公式中的变量的值的单个值,向量或矩阵。 如果要使用向量,则将其指定为列向量非常重要。 你以后会明白为什么。 这背后的关键是,对于要用于替换的x每个值,它将用x替换整个公式。 换句话说,如果你做out = ...

“静态”意味着固定,“工作空间”是Matlab称之为存储所有变量的地方。 对于非嵌套函数,当Matlab位于函数的开头时,工作空间开始为空; 随着Matlab继续通过函数的代码行,它不断向工作区添加更多变量。 对于具有嵌套函数的函数,Matlab首先解析函数以查看将创建的变量(它专门查找x =类型行),然后创建所有这些变量(值为“未分配”),然后仅执行它开始贯穿代码; 但是在运行代码时,它永远不会创建新的变量。 这就是代码的原因 function TestNestedFunction

syms x...

请参阅Bye MATLAB,hello Python,感谢Sage提供从MATLAB迁移到Python的第一手经验。 See Bye MATLAB, hello Python, thanks Sage for a first-hand experience of migrating from MATLAB to Python.

从R2017a开始,使用“lhs”和“rhs”作为 syms x

expr = [1-x^2==2*y; 1+x^2==x+y];

lhsExpr = lhs(expr)

lhsExpr =

1 - x^2

x^2 + 1

rhsExpr = rhs(expr)

rhsExpr =

2*y

x + y

Starting R2017a, use "lhs" and "rhs" as syms x

expr = [1-x^2==2*y; 1+x^2==x+y];

lhsExpr = l...

我担心你唯一可以做的就是使用subs来做这个,但你可以将它包装在这样的函数中: function df = my_jacobian(f, x)

x_ = sym('a', size(x));

f_ = subs(f, x, x_);

df_ = jacobian(f_, x_);

df = subs(df_, x_, x);

end

使用此功能,您可以计算您的jacobian,类似于以下示例: syms x(t) y(t)

f = 2*diff(x(t), t)...

相关文章

中文名: MATLAB及应用 作者: 胡鹤飞 图书分类: 软件 资源格式: PDF

...

中文名: MATLAB智能算法30个案例分析 作者: 史峰 王辉 郁磊 胡斐

...

中文名: 模式识别与智能计算:MATLAB技术实现(第2版) 作者: 杨淑莹 图书分类:

...

中文名: 数字图像处理与机器视觉:Visual C++与Matlab实现 作者: 张铮 图

...

js对文字进行url编码涉及3个函数:escape,encodeURI,encodeURICompon

...

在oracle9i中如何编写sql或者存储过程来知道执行sql或者函数花费的时间? 比如:我有两种s

...

Distributed RPC(分布式RPC) The idea behind distribute

...

什么是Combiner Functions “Many MapReduce jobs are limi

...

@符号是特殊而又实用的C#符号。 比如它在string中的应用。 1 字符@表示,其后的字符串是个“逐

...

实现接口: com.bj58.oceanus.core.shard.Function 实现方法: pu

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值