My Math Forum mathematica

 Math Software Math Software - Mathematica, Matlab, Calculators, Graphing Software

 January 10th, 2012, 08:53 AM #1 Joined: Dec 2011 Posts: 8 Thanks: 0 mathematica hi all I am new in using mathematica , I need to excute this algorithem but I have no idea how to start hope you could help me. 1-set n(max)=(cb-cop)/(cmea+cit). 2-set n=1 3-set m(max)=(cb-cit*n)/(cop+ cmea*n) 4-set m=1 5-find f such that (cop*f*m+cmea*n*m+cit*n) <=cb 6-calculate G(f,l,n). 7-set m=m+1 and repeat steps and 6 until m=m(max). 8-set n=n+1,and repeat steps 3 to 7until n=n(max). 9- the optimal solution G"(f",l",n") can be obtained as min G(f,l,n).
 January 12th, 2012, 11:28 AM #2 Joined: Jan 2012 Posts: 6 Thanks: 0 Re: mathematica Code: nMax=(cb-cop)/(cmea+cit); gfln=Reap[Do[mMax=(cb-cit*n)/(cop+ cmea*n); Do[f=cb-(cmea*n*m+cit*n)/(cop*m);(*ASSUMING cop*m never equal to zero*) Sow[G(f,l,n)][[2,1]]; ,{m,mMax}];(*ASSUMING you meant to write "repeat steps 5 and 6"*) ,{n,nMax}]]; optimalsolution=Min[gfln]
 January 12th, 2012, 12:59 PM #3 Joined: Jan 2012 Posts: 6 Thanks: 0 Re: mathematica Note: Correcting my errors in translating 6-calculate G(f,l,n). I Apologize. Code: nMax=(cb-cop)/(cmea+cit); gfln=Reap[Do[mMax=(cb-cit*n)/(cop+ cmea*n); Do[f=cb-(cmea*n*m+cit*n)/(cop*m);(*ASSUMING cop*m never equal to zero*) Sow[G[f,l,n][[2,1]]]; ,{m,mMax}];(*ASSUMING you meant to write "repeat steps 5 and 6"*) ,{n,nMax}]]; optimalsolution=Min[gfln]
 January 12th, 2012, 01:47 PM #4 Joined: Jan 2012 Posts: 6 Thanks: 0 Re: mathematica Another error because at the moment I can't test this before posting. I apologize. Code: nMax=(cb-cop)/(cmea+cit); gfln=Reap[Do[mMax=(cb-cit*n)/(cop+ cmea*n); Do[f=cb-(cmea*n*m+cit*n)/(cop*m);(*ASSUMING cop*m never equal to zero*) Sow[G[f,l,n]]; ,{m,mMax}];(*ASSUMING you meant to write "repeat steps 5 and 6"*) ,{n,nMax}]][[2,1]]; optimalsolution=Min[gfln]
 January 12th, 2012, 02:27 PM #5 Joined: Dec 2011 Posts: 8 Thanks: 0 Re: mathematica Thank you very much dear Bill...you saved my life .But I need your help again ,by this code i get the minimum of G(f,l,n),i need to obtain the values of f ,l and n that correspond this minimum..how could i do it ? Code: u = 1.0; d = 1000.0; m = 2.0; p = 0.1; \[Sigma] = 2.5; cb = 7200.0; cop = 20.05; cmea = 4.65; cit = 130.0; nMax = (cb - cop)/(cmea + cit); gfkn = Reap[Do[kMax = (cb - cit*n)/(cop + cmea*n); Do[f = cb - (cmea*n*k + cit*n)/(cop*k);(*ASSUMING cop* k never equal to zero*) Sow[E^(2 (-m + Log[d] + (u^2 + 3/\[Pi]^2 (6 \[Sigma]^2 E^(-2 m))/( f^2 k (k + 1) (2 k + 1)))^(1/2) Log[p/(1 - p)])) (1 - 2 E^((3 (u^2 + 3/\[Pi]^2 (6 \[Sigma]^2 E^(-2 m))/( f^2 k (k + 1) (2 k + 1))) (1 + Log[p/(1 - p)]^2/( 1 + (u^2 + 3/\[Pi]^2 (6 \[Sigma]^2 E^(-2 m))/( f^2 k (k + 1) (2 k + 1))))))/(2 n)) + E^(( 6 (u^2 + 3 (6 \[Sigma]^2 E^(-2 m))/(f^2 k (k + 1) (2 k + 1))) (1 + Log[p/(1 - p)]^2/( 1 + (u^2 + 3/\[Pi]^2 (6 \[Sigma]^2 E^(-2 m))/( f^2 k (k + 1) (2 k + 1))))))/n))];, {k, kMax}];, {n, nMax}]][[2, 1]]; optimalsolution = Min[gfkn]
 January 12th, 2012, 08:57 PM #6 Joined: Jan 2012 Posts: 6 Thanks: 0 Re: mathematica There are two parts to the answer. First part. Instead of Sow[G[f,l,n]]; use Sow[{G[f,l,n],f,l,n}]; That will save the value AND the parameters for that value as a list. Second part. Now Min[gfln] is no longer sufficient to extract the data you want, but Sort can be a substitute. try First[Sort[gfln,(First[#1]
 February 13th, 2012, 10:43 AM #7 Joined: Dec 2011 Posts: 8 Thanks: 0 Re: mathematica thank you very much, I still have a problem with this code ,the parameter k should change when I change the cb,cop,cmea, or cit ,but this code keep giving me k=1 for all cases what should i do d = 100.0; m = 2.0; u = 1.0; p = 0.1; \[Sigma] = 2.5; cb = 1700.0; cop = 29.05; cmea = 60.65; cit = 18.0; nMax = (cb - cop)/(cmea + cit); gfkn = Reap[Do[kMax = (cb - cit*n)/(cop + cmea*n); Do[f <= (cb - (cmea*n*k + cit*n))/(cop*k); Sow[{E^(2 (-m + Log[d] + (u^2 + 3/\[Pi]^2 (6 \[Sigma]^2 E^(-2 m))/( f^2 k (k + 1) (2 k + 1)))^(1/2) Log[p/(1 - p)])) (1 - 2 E^((3 (u^2 + 3/\[Pi]^2 (6 \[Sigma]^2 E^(-2 m))/( f^2 k (k + 1) (2 k + 1))) (1 + Log[p/(1 - p)]^2/( 1 + (u^2 + 3/\[Pi]^2 (6 \[Sigma]^2 E^(-2 m))/( f^2 k (k + 1) (2 k + 1))))))/(2 n)) + E^(( 6 (u^2 + 3 (6 \[Sigma]^2 E^(-2 m))/(f^2 k (k + 1) (2 k + 1))) (1 + Log[p/(1 - p)]^2/( 1 + (u^2 + 3/\[Pi]^2 (6 \[Sigma]^2 E^(-2 m))/( f^2 k (k + 1) (2 k + 1))))))/n)), f, k, n}];, {k, 1, kMax}];, {n, 1, nMax}]][[2, 1]]; First[ Sort[gfkn, (First[#1] < First[#2]) &]]
 February 14th, 2012, 10:27 AM #8 Joined: Jan 2012 Posts: 6 Thanks: 0 Re: mathematica I am concerned by your line: ... Do[f <= (cb - (cmea*n*k + cit*n))/(cop*k); ... Did you perhaps mean Do[f=(cb - (cmea*n*k + cit*n))/(cop*k); because otherwise you are just comparing an uninitialized f against an expression and then throwing away the result. But that still doesn't seem to change your k when I fiddle with cb,cop,cmea,cit. If I change your last line of code to Sort[gfkn, OrderedQ[{First[#1], First[#2]}] &] // MatrixForm then it appears it is correctly sorting on the first column and for small values of the first column k just seems to usually be 1. Can you provide some specific values for cb,cop,cmea,cit where k should not be 1?

 Tags mathematica

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post The_Fool Calculus 5 July 10th, 2012 12:24 PM phoebe Math Software 3 February 2nd, 2012 09:17 AM sivela Math Software 2 April 15th, 2010 03:30 PM carXunderwater Math Software 1 March 4th, 2010 09:12 PM billymac00 Number Theory 5 September 6th, 2009 09:59 PM

 Contact - Home - Top