Solving Nonlinear Equations for Real & Positive y with MATLAB

  • MATLAB
  • Thread starter narciss
  • Start date
  • Tags
    Nonlinear
In summary, the conversation is about solving a mathematical problem using MATLAB. The problem involves finding real and positive solutions for a given equation with different values of k. The output of the program provides multiple complex solutions, but the user wants to access only the real and positive solutions. The solution involves using the "solve" and "double" functions in MATLAB to filter out the desired solutions.
  • #1
narciss
2
0
hi,I want to solve this problem g=(2*k-1)*y^(k-1)-((1-y^(k-1))/(1-y));
with different k and compute real and positive y so I wrote this problem in MATLAB :

clear
clc
syms y k
g=(2*k-1)*y^(k-1)-((1-y^(k-1))/(1-y));
s=input('k=');
r=subs(g,k,s);
d=solve(r,y)


for example for k=23, d is :
d =

-0.81811283931382571520293209145876
0.94489877227954174128854689719319
0.49817720691940700053271532985098*i + 0.70274012247267906457267465202869
0.8277411118536081744820266610328*i + 0.091223969497361113040570073727308
0.70274012247267906457267465202869 - 0.49817720691940700053271532985098*i
0.77618594017326471476948567264672*i + 0.31945829898333809762888417711851
0.66408105322563369425240846687412*i + 0.52794201445903356864325220084683
- 0.81578326314656692336119246927549*i - 0.14054570047225202321477692915064
0.31945829898333809762888417711851 - 0.77618594017326471476948567264672*i
- 0.43526833501145662377255480027818*i - 0.69440096303504092329530844495529
- 0.2261452657095273445108974567173*i - 0.78660416168374227478532096534373
0.74176587152245045340265355683142*i - 0.35904590888321456580860087033279
0.83524761241076784983622123703462 - 0.2867812308408161156768712484769*i
- 0.61159735082182773643471203553956*i - 0.5482971391206768085492914227296
0.2261452657095273445108974567173*i - 0.78660416168374227478532096534373
- 0.74176587152245045340265355683142*i - 0.35904590888321456580860087033279
0.81578326314656692336119246927549*i - 0.14054570047225202321477692915064
0.61159735082182773643471203553956*i - 0.5482971391206768085492914227296
0.52794201445903356864325220084683 - 0.66408105322563369425240846687412*i
0.2867812308408161156768712484769*i + 0.83524761241076784983622123703462
0.43526833501145662377255480027818*i - 0.69440096303504092329530844495529
0.091223969497361113040570073727308 - 0.8277411118536081744820266610328*i

but I want real and positive y, how can I access real and poitive number in d?
 
Physics news on Phys.org
  • #2
clear
echo on
syms y k
g=(2*k-1)*y^(k-1)-((1-y^(k-1))/(1-y));
s=input('k=');
r=subs(g,k,s);
d=solve(r,y);
d1=double(d);
a=d1>0&imag(d1)==0;
disp(d1(a))
 

Related to Solving Nonlinear Equations for Real & Positive y with MATLAB

1. How can I solve a nonlinear equation for real and positive y using MATLAB?

To solve a nonlinear equation for real and positive y using MATLAB, you can use the fzero function. This function uses the bisection method to find the roots of a given equation. You will need to provide the equation, an initial guess for the root, and an upper and lower bound for the root. The output will be the value of y that satisfies the equation.

2. Can I solve multiple nonlinear equations at once with MATLAB?

Yes, you can solve multiple nonlinear equations at once with MATLAB by using the fsolve function. This function uses the Newton-Raphson method to find the roots of a system of equations. You will need to provide the equations, an initial guess for the roots, and an upper and lower bound for the roots. The output will be a vector of values that satisfy all the equations.

3. What if my nonlinear equation has more than one solution?

If your nonlinear equation has more than one solution, the fzero and fsolve functions will only find one of the solutions. To find all the solutions, you can use the roots function. This function calculates all the roots of a polynomial equation and returns them as a vector.

4. Can I plot the solutions of my nonlinear equation using MATLAB?

Yes, you can plot the solutions of your nonlinear equation using the fplot function. This function plots a function over a specified range of values. You can use the output of the fsolve or roots function as the input for fplot to visualize the solutions of your equation.

5. Are there any other methods for solving nonlinear equations with MATLAB?

Yes, there are other methods for solving nonlinear equations with MATLAB. Some other commonly used methods include the secant method, the Brent method, and the Golden Section method. These methods can be accessed through the fzero function by specifying the algorithm as an input argument. You can also find additional functions and toolboxes for solving nonlinear equations in the MATLAB File Exchange.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
962
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
3K
  • Precalculus Mathematics Homework Help
Replies
4
Views
841
Back
Top