tags:

views:

54

answers:

1

Hallo friends, I want to figure out the following problem: Suppose,we have expression like,

syms t k A0
r1=(-1+k-3/4*k*A0^2)*sin(t)+1/4*k*A0^2*sin(3*t)+A0*sin(5*t);

we want to remove the coefficients of sin(t) and solve it for A0 & finally put this value to the rest of the expression.How can we do it without cut and paste.

A: 

I don't know what symbolic capabilities were available for MATLAB version 5.3.1, but you can solve your problem using the functions COEFFS, SUBS, and SOLVE from the current Symbolic Math Toolbox:

>> eqCoeffs = coeffs(r1,sin(t));  %# Get coefficients for polynomial in sin(t)
>> b = eqCoeffs(2);               %# Second coefficient is what you want
>> bValue = 1;                    %# The value to set the coefficient equal to
>> newA0 = solve(subs('b = bValue'),A0)  %# Solve for A0

newA0 =

 -(2*3^(1/2)*(k - 2)^(1/2))/(3*k^(1/2))  %# Note there are two values since
  (2*3^(1/2)*(k - 2)^(1/2))/(3*k^(1/2))  %#   A0 is squared in the equation

>> r2 = subs(r1,A0,newA0)                %# Substitute the new A0 values into r1

r2 =

 sin(t) + (sin(3*t)*(k - 2))/3 - (2*3^(1/2)*sin(5*t)*(k - 2)^(1/2))/(3*k^(1/2))
 sin(t) + (sin(3*t)*(k - 2))/3 + (2*3^(1/2)*sin(5*t)*(k - 2)^(1/2))/(3*k^(1/2))

Note that the coefficients of sin(t) in the two equations of r2 are equal to 1 (the value I used for bValue).

gnovice

related questions