how can i solve these equations to get the variables??

hi; i am working on my thesis and i made an iteration process to solve these equations for x(i),a(i),b(i),Cx(i),Cy(i),Cl(i) and Cd(i). all other variables that you seen are just given before this sector of the code. and i made the wanted variables as vectors in the first so matlab can deal with them as vectors just that. the problem is that matlab is giving me the answer for (i=5:10), but for(i=1:4) the answer is not coming and the iteration process goes to infinity. is there any other way to solve these equations ?? like dealing with them as simultaneous equations or is there a code to solve them?? thank you for help
if true
% code
end
x=[1:10]; Cl=[1:10]; Cd=[1:10]; a=[1:10]; b=[1:10];
Cx=[1:10]; Cy=[1:10]
for i=1:10
a(i)=0; b(i)=0;
diff_a=1; diff_b=1;
iteration_count=0;
while diff_a >= 1e-7 || diff_b >= 1e-7
x(i)=(atand((1-a(i))/((1+b(i))*H*(i/10))))-B(i);
if x(i)<= 20
Cl(i)= -0.0004*x(i)^3 + 0.0059*x(i)^2 + 0.0759*x(i) + 0.0097;
else
Cl(i)= 6*10^(-6)*x(i)^3 - 0.0015*x(i)^2 + 0.101*x(i) - 0.9405;
end
Cd(i)= -5*10^(-6)*x(i)^3 + 0.0006*x(i)^2 - 0.0018*x(i) - 0.0045;
Cx(i)=(Cl(i))*cosd(x(i)+B(i))+(Cd(i))*sind(x(i)+B(i));
Cy(i)=(Cl(i))*sind(x(i)+B(i))-(Cd(i))*cosd(x(i)+B(i));
a_next = 1/(((4*sind(x(i)+B(i))*sind(x(i)+B(i)))/(G(i)*Cx(i)))+1);
b_next = 1/(((4*sind(x(i)+B(i))*cosd(x(i)+B(i)))/(G(i)*Cy(i)))+1);
diff_a = abs(a_next - a(i));
diff_b = abs(b_next - b(i));
a(i) = a_next;
b(i) = b_next;
iteration_count = iteration_count + 1
end
end

2 Comments

I do not follow the reason you are using degrees instead of radians ?
I can't really mentally simulate this without an idea of the range of the values in B(1:5), or the value in H.

Answers (5)

why no answer

5 Comments

I spent the time passing a kidney stone. Thanks for asking!
Sorry about the renal calculus, Walter. I understand they’re about as far from having fun as it’s possible to get.
Amjed — We cannot simulate your code because we don’t have values for B and G. If we can’t simulate it, we can’t figure out what may be wrong with i = 1:4, since it seems to work for higher values. (Also, please don’t use ‘i’ or ‘j’ as loop indices. MATLAB uses them for its imaginary operators.)
hellow; thank you for help . i use sine and cosine in degree because the equations giving them in degree . take the value of H as 6 . take the value of B from i=1 to i=10: 29 23 16 13 9 7 6 5 4 3 . take the value of G: 2.7 2 1.6 1.3 0.9 0.7 0.6 0.5 0.4 0.3 . today i decrease the error from 1e-7 to 1e-2 and that gave me the answers but when i try to solve the equations using (fsolve) i get different answer !!. and is there a problem of making the loop i and j ?? i see all use i,j,k for loops. now i am asking if there another function or good way to solve these kind of equations in matlab. thank you very much
i am saying that the answers i get after making the error 1e-2 is good and right. but i need to know if there is a better way of solving these equations because in another part ((when i change the values of B)) of my code , my iteration process also went to infinity !!
and sorry for your stone Mr.Walter. it is very important to drink a large amount of water in morning just after you wake up. i was having stones and the water made me better.
is it very hard question ??!!! no one help
I see no reason to believe that the iterative procedure you have set up will necessarily converge. You were lucky with B(i) and G(i) for i from 5 to 10, but it clearly failed to converge for 1 to 4. You need to use matlab's symbolic 'solve' function or the numerical 'fsolve' function to find a simultaneous solution for all seven equations, rather than this apparently blind iteration.
Just to give you a very simple iteration that will fail, suppose you want to solve for the single unknown x in the equation
x = -2*x + 3
and suppose we naively start with x(1) = 0 and do the iteration
x(n+1) = -2*x(n) + 3
in the hope that it will eventually converge to the answer x = 1. Unfortunately, it does this instead:
x = 0,3,-3,9,-15,33,-63,...
and is clearly never going to arrive at the correct answer.
I claim that your iteration with the seven equations and seven unknowns is similar in concept to this simple example. You have no reason to suppose that it will successfully converge.

2 Comments

thanks for help; but in the example you gave you use one equation !! this is not iterative process and you have just one variable !! but ok i tried the "fsolve" and i will retry it today and will give the feedback
how can input the given values of B and G in the function ? when i run the function he said that B and G are undefined !! while they are already defined in the program
i really disappointed with this site

This question is closed.

Asked:

on 23 Apr 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!