Solving Nonlinear Equations for Real & Positive y with MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter narciss
  • Start date Start date
  • Tags Tags
    Nonlinear
Click For Summary
SUMMARY

This discussion focuses on solving the nonlinear equation g=(2*k-1)*y^(k-1)-((1-y^(k-1))/(1-y)) using MATLAB. The user successfully implements the equation and retrieves complex solutions for various values of k, specifically k=23. To isolate real and positive solutions, the user employs MATLAB's double function and logical indexing to filter the results. The final output displays only the real and positive values of y.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of symbolic computation in MATLAB
  • Knowledge of nonlinear equations and their properties
  • Basic concepts of complex numbers and filtering techniques
NEXT STEPS
  • Explore MATLAB's symbolic toolbox for advanced equation solving
  • Learn about logical indexing in MATLAB for data filtering
  • Investigate methods for visualizing complex solutions in MATLAB
  • Study additional techniques for solving nonlinear equations in numerical analysis
USEFUL FOR

Mathematics students, engineers, and researchers working with nonlinear equations in MATLAB, particularly those seeking to extract real and positive solutions from complex 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 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K