Message Boards Message Boards

GROUPS:

NSolve works with not a valid variable or gives no solution

Posted 14 days ago
271 Views
|
13 Replies
|
0 Total Likes
|

Hello everyone, if some of you might help me with this question: If I run a first program it gives me an answer of 1 and then after I run this program a second program with NSolve gives me the right results but stating that there are not valid variables..If it runs without any statements for errors it returns an empty set of solutions... Running the first program I know there is a set of solutions for the result of 1...but NSolve will not give me these results if I state ==1. First program with the solutions I would expect in the second program: Why is that, how can solve it? I wanted the program to work for a single number chosen ( known prime) so it would give me the related odd number that respect the formula of x1.

sq=Table[j,{j,100000}]
sq11=Table[j,{j,100,10000}]
x=Select[sq,OddQ,(2002)]
n=Select[sq,PrimeQ,(2002)]
n1=n
r=0
x1=(((((n+r)*x)+n+r))/(n+r))/(((((n)*(x+r)+(x+r))))/(n1))
b=IntegerPart[x1]

Second program with Nsolve:

sq=Table[j,{j,100000}]
sq11=Table[j,{j,100,10000}]
n=Select[sq,PrimeQ,(2002)]
n1=Select[sq,PrimeQ,(2002)]
r=0
NSolve[(((((n+r)*x)+n+r))/(n+r))/(((((n)*(x+r)+(x+r))))/(n1))==1,{x}]
13 Replies
Posted 13 days ago

Hi Luis,

This is a list of expressions involving x

exp = (((((n+r)*x)+n+r))/(n+r))/(((((n)*(x+r)+(x+r))))/(n1))

Are you trying to find a value of x in each of those expressions that give the value 1? Then

eqn = Thread[exp == 1]
NSolve[#, x] & /@ eqn

The result is pretty obvious given how exp is constructed.

So I must be missing something. What exactly are you trying to solve and what is the relationship between your two programs?

Hello Dr.Rohit...once again you thank you so much for your interest...you see if you substitute the value of x with odd numbers it will give also 1 for a given n1 prime, and it follows that they are related to each prime accordingly 1->2,3->5,5->7,7_>11 and so on. I have done it in isolation to verify and it is true ( just try the first program...it will give 1 for all the integer part b. If I run the first program that I wrote it will give only 1 as an answer...if then i run the second program it says x is not a valid variable but lists the results as only odd numbers from 1 to 4003... Can I choose x to be used in NSolve[#,x] &/@eqn to be only odd numbers to be tried? if yes then I think what I want could be done...because it will give me as results the corresponding odd numbers x selected in the first program "x=Select[sq,OddQ,(2002)]". I hope I have clarified enough for you to help me ...what I think is possible is to give a related odd number that could then be used to relate to the prime position... it is the case for the 3999 ( 2000th odd) that could then be related to 2000th prime. Thanks once again.

As a matter of fact it already is given as answer in

{(1+x)/x==1,(3+3 x)/(4 x)==1,(5+5 x)/(6 x)==1,(7+7 x)/(8 x)==1,(11 (9+9 x))/(90 x)==1,(13 (11+11 x))/(132 x)==1, [CenterEllipsis]1991[CenterEllipsis] ,(17383 (3995+3995 x))/(15964020 x)==1,(17387 (3997+3997 x))/(15980006 x)==1,(17389 (3999+3999 x))/(15996000 x)==1,(17393 (4001+4001 x))/(16012002 x)==1,(17401 (4003+4003 x))/(16028012 x)==1} large output show less show more show all set size limit...

it is the numbers in between* * in italic that are related to each other ...they indirectly give me the position of the prime, but by the relation to the position of the odd number...I just needed to get them printed.

sq=Table[j,{j,100000}]
    sq11=Table[j,{j,100,10000}]
    x=Select[sq,OddQ,(2002)]
    n=Select[sq,PrimeQ,(2002)]
    r=0
    exp=(((((n+r)*x)+n+r))/(n+r))/(((((n)*(x+r)+(x+r))))/(n1))
    eqn=Thread[exp == 1]
    NSolve[#, n1] & /@ eqn

Even though it gives me false it should be giving me true as I showed in the first program...notice that I changed the variables ...this is closer to what I wanted.

Posted 13 days ago

It is still not clear to me what you are trying to do. In the above code the result from NSolve is a list like

{{{n1 -> 1.5}}, {{n1 -> 3.}}, {{n1 -> 5.}}, {{n1 -> 7.}}, {{n1 -> 10.8}}, {{n1 -> 12.8333}}, ...}

If this is closer to what you want, then what are you trying to extract from this list? Using your original problem 2 code is this what you are trying to do?

ClearAll[x, sq, sq11, n, n1, r, exp, eqn]

sq = Table[j, {j, 100000}];
sq11 = Table[j, {j, 100, 10000}];
n = Select[sq, PrimeQ, (2002)];
n1 = Select[sq, PrimeQ, (2002)];
r = 0;

exp = (((((n + r)*x) + n + r))/(n + r))/(((((n)*(x + r) + (x + r))))/(n1));

eqn = Thread[exp == 1];
sol = NSolve[#, x] & /@ eqn;

sol[[2000]]
(* {{x -> 17389.}} *)

If you do (nx)+n/n for n=prime and x=odd number you get an even number from 2-400 for the first 200 numbers both first 200 primes and first 200 odds. Doing the calculus one by one with numbers it would be like this : ((1223 * 399)+1223)/1223 =400 ; ( (1229401)+1229)/1229=402 and so on. Now if you do ((nx)+x)/n for the same numbers 1223, 1229 (200th and 201th prime), you get : ((1223399)+399)/1223=399,324 , and ((1229*401)+401)/1229=401,32.. So it is like you transform the prime numbers lis tinto a listo f consecutive even numbers from 2 to 400 and when you use x( odd number in the place of n in the + sign) you get an odd number that is related to the even number minus 1 with a decimal.. so if the result is Always related like this I should be able to get the numbers x and n , x if i use n and n i use x.

sq=Table[j,{j,100000}]
sq11=Table[j,{j,100,10000}]
n=Select[sq,OddQ,(2002)]
n1=Select[sq,PrimeQ,(2002)]
r=0
exp=(((n*x)+n)/n)==((((n*x)+x)/n))+1
eqn=Thread[exp ]
NSolve[#, x] & /@ eqn

Sorry Dr. Rohit my computer seems not to be working properly...for the equation above it gave me the results in one try then it changes the answer if I run the program again and again.

For instance the program below returns `

sq=Table[j,{j,100000}]
sq11=Table[j,{j,100,10000}]
n=Select[sq,PrimeQ,(2002)]
n1=Select[sq,PrimeQ,(2002)]
r=0
exp=(((((n+r)*x)+n+r))/(n+r))/(((((n)*(x+r)+(x+r))))/(n1))
eqn=Thread[exp == 1]
NSolve[#, x] & /@ eqn



{NSolve[False,{1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75, \[CenterEllipsis]1926\[CenterEllipsis] ,3929,3931,3933,3935,3937,3939,3941,3943,3945,3947,3949,3951,3953,3955,3957,3959,3961,3963,3965,3967,3969,3971,3973,3975,3977,3979,3981,3983,3985,3987,3989,3991,3993,3995,3997,3999,4001,4003}], \[CenterEllipsis]2000\[CenterEllipsis] , \[CenterEllipsis]1\[CenterEllipsis] }

But what it calls false are the odd numbers that should be x

Posted 12 days ago

You really have to be careful when running your code experiments because sometimes symbols are defined by a previous computation and sometimes they are not so the results can change depending on previous evaluations. You may also have other notebooks open that are running against the same kernel and expressions evaluated in them will be shared with all notebooks with the same context.

I strongly suggest that you evaluate the following before each of your experiments to make sure all symbols are cleared and there are no lingering definitions from previous experiments.

ClearAll[Evaluate[Context[] <> "*"]]

Copy/paste this (clear, followed by your code above) and you should see the correct output from NSolve and you will get the same result every time the group of cells is evaluated.

ClearAll[Evaluate[Context[] <> "*"]]
sq=Table[j,{j,100000}];
sq11=Table[j,{j,100,10000}];
n=Select[sq,PrimeQ,(2002)];
n1=Select[sq,PrimeQ,(2002)];
r=0;
exp=(((((n+r)*x)+n+r))/(n+r))/(((((n)*(x+r)+(x+r))))/(n1));
eqn=Thread[exp == 1];
sol=NSolve[#, x] & /@ eqn

sol[[2000]]
(* {{x -> 17389.}} *)

You are really awesome Dr Rohit, but your help made me see more than just codes, observing the results I have noticed a relation between prime numbers that will help to find the approximate position of a prime number without the need to list of all the previous prime numbers, it is a rule of three between decimal numbers, it appeared after i ran one of your codes with a very small change...but It is preliminary...as soon as I have worked it out I will let you know...God bless you.

enter code hereFor instance the program below returns `

sq=Table[j,{j,100000}]
sq11=Table[j,{j,100,10000}]
n=Select[sq,PrimeQ,(2002)]
n1=Select[sq,PrimeQ,(2002)]
r=0
exp=(((((n+r)*x)+n+r))/(n+r))/(((((n)*(x+r)+(x+r))))/(n1))
eqn=Thread[exp == 1]
NSolve[#, x] & /@ eqn

`

{NSolve[False,{1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75, [CenterEllipsis]1926[CenterEllipsis] ,3929,3931,3933,3935,3937,3939,3941,3943,3945,3947,3949,3951,3953,3955,3957,3959,3961,3963,3965,3967,3969,3971,3973,3975,3977,3979,3981,3983,3985,3987,3989,3991,3993,3995,3997,3999,4001,4003}], [CenterEllipsis]2000[CenterEllipsis] , [CenterEllipsis]1[CenterEllipsis] } large output show less show more show all set size limit...

But what it calls false are the odd numbers that should be x

Hello Dr. Rohit, as I told you there was a modified version of the program you made so that I found a relation for the x value, it comes about that it varies according to the numbers used in the comparison:

sq=Table[j,{j,100000}]
sq11=Table[j,{j,100,10000}]
n1=Select[sq,OddQ,(2002)]
n=17389
r=0
exp=(((n*x)+n)/n)==((((n*x)+x)/n))-1
eqn=Thread[exp ]
NSolve[#, x] & /@ eqn
sq=Table[j,{j,100000}]
sq11=Table[j,{j,100,10000}]
n2=17393
n1=17389
r=0
exp=(((n2*x)+n2)/n2)==((((n2*x)+x)/n2))-1
eqn=Thread[exp ]
NSolve[#, x] & /@ eqn
exp=((((n2*x)+n2)/n2)-((((n2*x)+x)/n2))/17389)-1==(((n*x)+n)/n)-((((n*x)+x)/n))-1
eqn=Thread[exp ]
NSolve[#, x] & /@ eqn

It gives true to the relation and gives me the value of x that should be considered when equaling the 2 equations, it just so happens that that number is the relation of p/p+1 p is a prime, which then led me to verify that they can be used in predicting the position of prime number without the need of a list, I Made a program to simulate the number interrelated between the 200th -400th prime with the 2000th to the 2200th prime , and I used the prime numbers selected only to have numbers to apply the formula and made a rule of 3 between them and its given position initially known of the first number, so the result of the following program gives the right position for the prime numbers n2 without having to use a list of primes, remember that I only used them to have numbers generated to try out the formula which at least for these conditions give a true result:

sq=Table[j,{j,100000}]
sq11=Table[j,{j,17389,100000}]
sq12=Table[j,{j,1223,100000}]
n1=Select[sq12,PrimeQ,(200)]
n=List[n1]
n2=Select[sq11,PrimeQ,(200)]
a=n1/(n1+1)
b=Select[sq,IntegerQ,(200)]
b1=a*b
c=b1/((n2/(n2+1)))
d=c*10
e=IntegerPart[d]
f=(e/10)+2000
IntegerPart[f]

result: {2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040,2041,2042,2043,2044,2045,2046,2047,2048,2049,2050,2051,2052,2053,2054,2055,2056,2057,2058,2059,2060,2061,2062,2063,2064,2065,2066,2067,2068,2069,2070,2071,2072,2073,2074,2075,2076,2077,2078,2079,2080,2081,2082,2083,2084,2085,2086,2087,2088,2089,2090,2091,2092,2093,2094,2095,2096,2097,2098,2099,2100,2101,2102,2103,2104,2105,2106,2107,2108,2109,2110,2111,2112,2113,2114,2115,2116,2117,2118,2119,2120,2121,2122,2123,2124,2125,2126,2127,2128,2129,2130,2131,2132,2133,2134,2135,2136,2137,2138,2139,2140,2141,2142,2143,2144,2145,2146,2147,2148,2149,2150,2151,2152,2153,2154,2155,2156,2157,2158,2159,2160,2161,2162,2163,2164,2165,2166,2167,2168,2169,2170,2171,2172,2173,2174,2175,2176,2177,2178,2179,2180,2181,2182,2183,2184,2185,2186,2187,2188,2189,2190,2191,2192,2193,2194,2195,2196,2197,2198,2199} ”

Hi Dr.Rohit just in case you would like to see what i am working on so you donot miss anything, as the truth does not belong to me i should no hide my experiments...as i told you there is a rule hiddenin prime numbers relation of p/p+1 that allow for the calculation of the position of the prime without having to require to list them:
I wrote in capital letters because are decimal numbers hard to grasp! Here are my latest results: Grand finale
1223 ÷ 1224 =0,9991830065359477124183 1 - ( 1223 ÷ 1224 ) = 0,000816993464052287581699346405228 0,000816993464052287581699346405228*200=0,1633986928104575163398 1-1633986928104575163398= 0,8366013071895425 0,8366013071895425 * 1223= 1023,1633986928104575163398(1) 1223- 1023,1633986928104575163398= 199,8366013071895225 + 0,1633986928104575163398 = 199,9999999999999800163=200

NOW IF I CHANGE THE POSITION TO 201
1223 ÷ 1224 =0,99918300653594771241830065359477 1-0,999183006535947712418300653 =0.00081699346405228758169934640522876 0.00081699346405228758169934640522876 *201= 0,164215686274509803921568627450 1-0,164215686274509803921568627450= 0,8357843137254901960784313725490 0,8357843137254901960784313725490*1223= 1.022,164215686274509803921568627(2)
COMPARING (1) AND(2) IF THE POSITION OF 200 IS CHANGED TO THE POSITION OF 201 THE LAST 2 DIGITS IN YELLOW BECOMES FARTHER FROM THE LAST 2 DIGITS OF THE ORIGINAL PRIME NUMBER 1223 ( 1023). SO IF ONE CAN COMPUTE UNTIL YOU GET THE VALUE OF (1) AND (2) THE FARTHER AWAY FROM THE LAST 2 DIGITS IT GETS MEANS THAT YOU ARE FAR AWAY FROM THE REAL POSITION, YOU JUST HAVE TO CHANGE THE NUMBER OF THE POSITION TO A NUMBER THAT GETS CLOSER TO THE LAST 2 DIGITS OF THE PRIME NUMBER TESTED. when considering numbers that have a position that is not a number ening in 00 as in 200, 2000 , 20000 you have to consider the rule described for the 412th prime below... as I say in capital letters if one can compute this it is new way of finding the position for unlimited size of prime number .... and could also be used as a counting of prime number as in teh prime number theorem only that more precise...i guess
In the case of 412th prime:

2837 / 2838=0,99964763918252290 1-0,99964763918252290=0.000352360817477096546 0.000352360817477096546 * 412=0,1451726568005637 1-0,1451726568005637=0,854827343199436222 0,854827343199436222*2837=2.425,14517265680056377730 2837-2.425,14517265680056377730= 411,8548273431994362 411,8548273431994362+0,14517265680056377730=411,999999999999999992692036645 (17 NINES)
NOW CHOOSING 413
0.000352360817477096546 * 413=0,14552501761804087 1-0,14552501761804087=0,85447498238195912 0,85447498238195912*2837=2.424,14552501761804188 2837-2.424,14552501761804188= 412,854474982381958113826+0.14552501761804188=412,999999999999999113826 (15 NINES) WHICH MIGHT AS WELL BE 413 BUT AGAINST 412 THERE IS A LESSER COUNTING OF DECIMALS 99999... SO THE CLOSER RESULT IS 412 FOR THE PRIME POSITION

Conclusion:

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract