how can i substitute some variables in a function with except of others

1 次查看(过去 30 天)
I have an equation with 137 parts, each part has its variables. I need to replace some variables in these parts and except others.
In the following is the example of equation that i want to process.
y = a0*b0*c0*k0 + a1*b0*c0*d*k0 + a0*b0*c0*k4*cos((pi*m)/3) + a0*b0*c0*k2*cos((pi*m)/6) + a0*b0*c4*k0*cos((pi*t)/6) + a0*b0*c2*k0*cos((pi*t)/12) + a0*b4*c0*k0*cos((pi*theta)/90) + a0*b2*c0*k0*cos((pi*theta)/180) + a0*b0*c0*k3*sin((pi*m)/3) + a0*b0*c0*k1*sin((pi*m)/6) + a0*b0*c3*k0*sin((pi*t)/6) ...
I need to replace (a0b0c0k0 with p1) in the first part, (a1b0c0k0 with p2 and leave d) in the second part, (a0b0c0k4 with p3 and leave (cos(pi*m/3))) for the third part and so on.
Please I you can help me with regard.
  2 个评论
Walter Roberson
Walter Roberson 2019-8-17
Are there any combinations of values that you want to replace in one part but not replace in the other? For example if you did
subs(y, a0*b0*c0*k0, p1)
then that would replace a0*b0*c0*k0 in all parts.

请先登录,再进行评论。

回答(2 个)

Mohammed Ismail
Mohammed Ismail 2019-8-17
but the combinatin is not the same in all part. it has different combination and need to be replace and i have 137 part in my equation.
  6 个评论
Mohammed Ismail
Mohammed Ismail 2019-8-19
thank u for y kinds. yes, i want to convert all the combination of a b c k and leave the sin cos and d.

请先登录,再进行评论。


Mohammed Ismail
Mohammed Ismail 2019-8-21
thank you for your assistant. Can i ask you some questions.
First, the benifit of using this (sin = @(expr) 1).
Second, when i put in the (sin = @(expr) 1) an (theta*pi/3) the stop and not take it.
  1 个评论
Walter Roberson
Walter Roberson 2019-8-21
You have a lot of terms involving multiplying several variables together and then multiply by a sin or cos term. One way to extract out the variables without the sin and cos terms is to temporarily redefine sin and cos as returning 1 so that
a0*b2*c1*d*k2*cos(theta*pi/3)
would evaluate as
a0*b2*c1*d*k2*1
Which is
a0*b2*c1*d*k2
It is a trick for stripping off the sin and cos terms leaving just the variables.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by