MATLAB Answers

use of "fsolve" function

2 views (last 30 days)
[EDIT: 20110722 22:40 CDT - merge additional material from Answer]
Hello there,
I have a new problem concerning the use of fsolve, it seems that it's not working for my function, I double checked my code but I can't really find my mistake. Since I am a new matlab user, I am asking for help to find out what's wrong with my script.
Thanks a lot in advance for helping,
Romain
Here below is my code:
function sol_ = ssrepeat1( i0_ , a0_ , m_ , n_ , e_ )
rad_ = 180 / pi;
initial_guess_ = [i0_ a0_];
options_ = optimset('MaxFunEvals',1e8);
var_ = fsolve(@(var_) ssrepeat( var_ , e_ , m_, n_), initial_guess_, options_ );
sol_(1) = var_(1) * rad_;
sol_(2) = var_(2);
end
function result_ = ssrepeat( var_ , e_ , m_ , n_ )
i_ = var_(1);
a_ = var_(2);
deg_ = pi / 180;
re_ = astro_constants(23);
mu_ = astro_constants(13);
we_ = 7.292115e-5;
J2_ = 1082.62622070e-6;
omega_dot_ = - sqrt( mu_ / a_ ^ 3 ) * ( re_ / a_ ) ^ 2 * ( ( 3 * J2_ ) / ( 2 * ( 1 - e_ ^ 2 ) ^ 2 ) ) * cos( i_ * deg_ );
w_dot_ = - sqrt( mu_ / a_ ^ 3 ) * ( re_ / a_ ) ^ 2 * ( ( 3 * J2_ ) / ( 2 * ( 1 - e_ ^ 2 ) ^ 2 ) ) * ( ( 5 / 2 ) * sin( i_ * deg_ ) ^ 2 - 2 );
n_tilt_ = - sqrt( mu_ / a_ ^ 3 ) * ( 1 - ( re_ / a_ ) ^ 2 * ( ( 3 * J2_ ) / ( 2 * ( 1 - e_ ^ 2 ) ^ ( 3 / 2 ) ) ) * ( ( 3 / 2 ) * sin( i_ * deg_ ) ^ 2 - 1 ) );
result_(1) = ( ( m_ / n_ ) / ( we_ - omega_dot_ ) ) - 1 / ( w_dot_ + n_tilt_ );
result_(2) = cos( i_ * deg_ ) + ( ( 2 * we_ * a_ ^ ( 3 / 2 ) * ( 1 - e_ ^ 2 ) ) / ( 3 * J2_ * re_ ^ 2 * sqrt( mu_ ) ) );
end
[Additional material moved from Answer]
I used the following inputs:
i0_ = 100 ° (orbital inclination)
a0_= 8000 km (semimajor axis)
m_ = 271 orbits
n_ = 19 nodal days
e_ = 0 (eccentricity for a circular orbit)
Here is what I get when I ran the script:
sol_ = ssrepeat1( 100 , 8000 , 271 , 19 , 0. )
Maximum number of function evaluations reached:
increase options.MaxFunEvals.
sol_ =
1.0e+03 *
-0.2544 7.7800
Or I should normally get something like:
98° and 7190 km
This script aims to design a sun-synchronous orbit repeating its ground track.
When I decrease my initial guess, the solution keeps on decreasing.
Last but not least, I basically tried to derive the following algorithm:
Hope it helps,
Romain

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 22 Jul 2011
What is it that makes you aware that it is not working? Is there an error message?
If you are going by the values returned, it would help if we had some sample inputs to work with.

  2 Comments

Romain W
Romain W on 22 Jul 2011
I used the following inputs:
i0_ = 100 ° (orbital inclination)
a0_= 8000 km (semimajor axis)
m_ = 271 orbits
n_ = 19 nodal days
e_ = 0 (eccentricity for a circular orbit)
Here is what I get when I ran the script:
sol_ = ssrepeat1( 100 , 8000 , 271 , 19 , 0. )
Maximum number of function evaluations reached:
increase options.MaxFunEvals.
sol_ =
1.0e+03 *
-0.2544 7.7800
Or I should normally get something like:
98° and 7190 km
This script aims to design a sun-synchronous orbit repeating its ground track.
When I decrease my initial guess, the solution keeps on decreasing.
Last but not least, I basically tried to derive the following algorithm:
http://www.cdeagle.com/omnum/pdf/ssrepeat.pdf
Hope it helps,
Romain
Walter Roberson
Walter Roberson on 23 Jul 2011
Perhaps it would make the code easier if you used sind() and cosd() instead of doing the trig conversion?
I see no reason at the moment why you would expect degrees for result(1) . I have not traced the math there but it appears to me that if anything you would be getting radians.
I suggest, by the way, that you command
format short g
so that you get rid of the "1.0e+03 *" part of your output.

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!