MATLAB Solving Nonlinear Equations for Real & Positive y with MATLAB

  • Thread starter Thread starter narciss
  • Start date Start date
  • Tags Tags
    Nonlinear
AI Thread Summary
The discussion focuses on solving the equation g=(2*k-1)*y^(k-1)-((1-y^(k-1))/(1-y)) in MATLAB for different values of k, specifically aiming to find real and positive solutions for y. The user provides a MATLAB script that defines the equation and attempts to solve it symbolically. When k=23 is used, the output includes several complex and negative solutions. To filter for real and positive values of y, the user seeks guidance on how to modify the script. The proposed solution involves converting the symbolic results to numerical values and applying logical conditions to extract only the real and positive solutions. The final MATLAB code snippet demonstrates how to achieve this by using logical indexing to display the desired results.
narciss
Messages
2
Reaction score
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
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))
 

Similar threads

Replies
4
Views
1K
Replies
2
Views
3K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
6
Views
2K
Back
Top