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

1 view (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 17 Aug 2019
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.

Sign in to comment.

Answers (2)

Mohammed Ismail
Mohammed Ismail on 17 Aug 2019
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 Comments
Mohammed Ismail
Mohammed Ismail on 19 Aug 2019
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.

Sign in to comment.


Mohammed Ismail
Mohammed Ismail on 21 Aug 2019
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 Comment
Walter Roberson
Walter Roberson on 21 Aug 2019
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.

Sign in to comment.

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!