solving an equation in matlab

4 Ansichten (letzte 30 Tage)
Alireza Lashgary
Alireza Lashgary am 29 Okt. 2016
Bearbeitet: Walter Roberson am 30 Okt. 2016
Hi Dear Friends
i have below summation :
and also i always know value of 'm' , for example m=14 so after doing my job in other place i get RG :
so now i have RG without knowing Fi's , so i want to solve that equation but i really dont have a idea for this in matlab !!
please help

Antworten (2)

Cory Johnson
Cory Johnson am 29 Okt. 2016
This can be done with a for loop and symbolic variables.
It is good practice to assign contstants at the top of the script:
m =14
Fi = ??
If you are solving for p, create a symbolic variable for that:
syms p
Use i as the loop variable, then convert the summation to an equation in MATLAB:
for i = 1:14
R_G = F_i*p^(m-i)*(1-p)^i
end
The last steps are to solve the symbolic equation with respect to p, some condition, then, if you have enough information to get rid of variables, convert it to double.
solved_p = solve(R_G == value, p);
final_p = double(solved_p)
Hope that helps!
  1 Kommentar
Alireza Lashgary
Alireza Lashgary am 29 Okt. 2016
no i dont want to solve for p ! p is variable and it other side of equation it remains as p ... i want to find F_i's ??

Melden Sie sich an, um zu kommentieren.


Roger Stafford
Roger Stafford am 30 Okt. 2016
I understand that you want to determine the values of Fi in your first RG expression, given m and the coefficients of an equivalent polynomial in p as in the second expression for RG. That is done by solving a set of m+1 linear equations in m+1 unknowns, namely the Fi values. Matlab can be used to accomplish this using the backslash operator. The necessary matrix of coefficients, M, in the linear equations can be constructed using the following code:
M = fliplr(eye(m+1));
M(m+1,:) = (-1).^(0:m);
for k = 2:m+1
M(1:m,k) = M(2:m+1,k-1)-M(1:m,k-1);
end
If C is a column vector of the polynomial coefficients of the given equivalent polynomial, C(1) + C(2)*p + C(3)*p^2 + ..., then solve the linear equations with:
F = M\C;
In your m = 14 example wherein the C values are:
C = [0;0;0;0;0;0;720;-4136;10741;-16356;15894;-10056;4034;-936;96]
you will find that the values of F turn out to be:
F = [1;14;89;340;869;1554;1949;1624;720;0;0;0;0;0;0]
That is, F0 = 1, F1 = 14, F2 = 89, F3 = 340, etc.

Community Treasure Hunt

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

Start Hunting!

Translated by