I have two equations and I am trying to solve them by (fsolve) and (solve) but I did not get the expecting results!
4 views (last 30 days)
Show older comments
kv=127.67;
kh=94.91;
M=0.53;
MU0=4*3.14e-7;
Mc=(3*MU0*M^2)/(2*pi);
eqn1=kv*xe-Mc*(1/(d+xe)^4)+Mc*((5*ye^2)/(2*(d+xe)^6))==0;
eqn2=kh*ye-Mc*ye*(1/(d+xe)^5)+Mc*ye*((5*ye^2)/(2*(d+xe)^7))==0;
%Need values of xe and ye
1 Comment
Walter Roberson
on 3 Apr 2025
d needs to be defined.
Question: is 3.14e-7 intended to be pi * 10^-7 or is the 3.14 just a coincidence?
Answers (1)
Simran
on 3 Apr 2025
I see that you’re trying to solve two non-linear equations to find the values of “xe” and “ye” using “fsolve” and “solve”. You can follow these steps to do so:
Using fsolve:
1.) Start by defining all the constants. Then define a function that calculates the residuals of the equations.
2.) Since it is “fsolve” function, provide an initial guess for the variables.
initial_guess = [0.1, 0.1]; % Adjust based on your problem context
3.) You can use “optimoptions” to configure the solver’s behavior, such as displaying iteration details.
4.) Call the “fsolve” function to find solution.
5.) Retrieve the solution from “fsolve”.
I got this solution from following the above steps:
Using “solve”:
- Now unlike numerical solvers, “solve” works with symbolic mathematics, allowing it to find exact solutions or expressions.
- Start by defining all constants that are part of your equations.
- Use “syms” to declare “xe” and “ye” as symbolic variables.
- Write your equations symbolically and call the “solve” to find all the solutions to the system of equations.
- Convert the symbolic solutions to numerical form using double.
- Iterate over the solutions and display each pair.
This is the result I got for this:
You can refer to these documentation links for more help:
0 Comments
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!