Generalized Eigenvalue Problem for Non-symmetric Matrices - matlab
I'm trying to solve a generalized eigenvalue problem. I have two matrices H and S such that:
HX=λSX
I need to find the eigenvalues λ. The matrices H and S are real, asymmetric, contains positive and negative decimal numbers and (can be) singular. I am using MATLAB and have tried two different approaches:
I used eig(H,S) command which uses QZ Algorithm to solve for eigenvalues.
I formed an equation in λ by using |H-λS|=0 and then solved for λ.
Here are the matrices: (both H and S are 24X24)
H=[0,0,0,0,192,1917.04064,10332.51505,40092.51227,125681.1486,338350.2206,811892.8294,1779728.921,3625982.355,6953387.916,12670976.81,22100000,37132930.27,60353006.25,95276316.19,146559937.4,220274060.5,324208411.9,468219308,664618721.8;
0,0,0,0,192,1893.475124,10051.90014,38308.22391,117609.6433,309187.9535,722364.2569,1537115.973,3030677.025,5606681.841,9824567.083,16426180.74,26355891.41,40770017.02,61031174.08,88683247.04,125403139.6,172926323.5,232944447.3,306974887;
0,0,0,0,192,1846.924351,9507.779872,34923.83828,102685.9158,256815.0258,566753.8301,1130503.089,2072244.588,3531888.862,5644710.273,8510616.36,12154554.65,16481872.51,21234784.98,25958063.51,29983201.26,32440241.94,32304892.86,28485362.66;
0,0,0,0,192,1778.534558,8732.953666,30281.20319,83090.50097,191433.6927,383369.9941,681577.7806,1089000.57,1571702.814,2043718.6,2360415.659,2327150.205,1728131.214,376286.8361,-1820993.208,-4791939.112,-8243585.409,-11638086.16,-14220529.21;
0,0,0,0,192,1689.989727,7773.203992,24831.36406,61515.88289,124689.9821,212051.9399,303583.89,356337.2627,308129.1939,94242.56924,-323226.8121,-920239.2345,-1583058.32,-2104105.201,-2214813.175,-1659107.74,-295993.1841,1796496.926,4254923.427;
0,0,0,0,192,1583.470126,6683.555129,19072.50505,40639.69537,66711.57632,81796.22718,60590.29663,-21861.2573,-171429.7577,-355062.5907,-492927.1661,-475398.2758,-208930.4549,320950.1747,997476.1882,1566265.895,1699768.472,1129529.762,-194208.6509;
0,0,0,0,192,1461.598622,5523.845413,13484.72812,22648.14037,23924.65349,4088.400074,-44523.67789,-110266.4937,-154796.0153,-124116.6074,18352.09343,250026.0416,467393.1673,513093.6957,258167.4211,-292568.7362,-936296.041,-1313188.428,-1070939.742;
0,0,0,0,192,1327.376095,4354.022806,8472.235861,8915.430969,-1775.330646,-26379.77787,-53287.95266,-55123.02039,-5131.095738,92963.75123,184430.9087,180646.3185,21137.78348,-252747.0452,-475735.34,-436097.8969,-33470.52706,583046.8515,1024123.527;
0,0,0,0,192,1184.107549,3229.595901,4321.651839,-104.2768198,-12455.61648,-25344.84529,-20852.91355,14642.78081,67162.133,88643.95935,29331.92183,-103721.9759,-215885.8219,-175668.2952,63339.97258,366040.1121,463007.7228,161145.8379,-426631.9431;
0,0,0,0,192,1035.320732,2197.653181,1181.837405,-4776.384006,-12614.95411,-10733.55999,10443.54925,39434.88701,40860.0242,-11919.57845,-90391.52336,-109544.5177,-4764.383231,169447.4417,238928.2291,63214.86651,-273067.0285,-452649.3406,-197417.4769;
0,0,0,0,192,884.6792681,1293.804398,-933.634351,-6033.445815,-7367.269353,3768.214436,22179.4179,22745.61092,-13409.71654,-59759.11695,-51183.66478,39553.74618,132447.0485,93359.81585,-98263.14966,-255824.9417,-144286.083,212696.4921,445204.5408;
0,0,0,0,192,735.8924507,540.3053094,-2124.343367,-5057.868211,-969.9812354,11405.43117,15940.52452,-5622.481002,-37623.47011,-29881.32575,35855.80045,87872.36995,28692.89466,-112944.5884,-154561.6584,24454.28757,254280.9736,202369.5839,-178659.2813;
0,0,0,0,192,592.6239049,-54.49033533,-2567.50857,-2988.296704,3941.876267,11526.38431,2233.953421,-22136.82236,-24139.16168,20459.96219,60268.45865,14532.0698,-88098.13253,-93277.95948,64910.42847,192595.8473,49803.13745,-244897.5404,-254777.9707;
0,0,0,0,192,458.4013779,-495.3380524,-2477.176593,-714.5839156,6392.684212,6873.986266,-9352.41825,-21134.06087,3844.754647,42020.47316,20505.10932,-58980.138,-70793.54333,51327.19794,141815.5672,6229.868714,-208390.0472,-130756.2533,224730.6889;
0,0,0,0,192,336.5298736,-798.086388,-2066.223865,1211.650343,6609.005295,832.2069828,-14542.95731,-9394.727768,23888.17206,29260.48864,-28610.53289,-63533.47519,18266.13986,110340.0964,20413.44929,-159630.1792,-99650.79156,191428.6434,224840.2275;
0,0,0,0,192,230.010273,-986.6727322,-1517.645248,2561.671612,5397.538212,-4248.815769,-13851.25499,3944.496017,28647.88724,2246.348802,-50351.46819,-19936.09886,77156.40402,55808.14847,-103790.0999,-116346.81,120768.0917,206007.3722,-114289.9057;
0,0,0,0,192,141.4654422,-1089.461027,-968.7547191,3346.025684,3627.717551,-7474.097775,-9965.085871,13492.9252,22500.21035,-20544.91549,-44251.15549,26525.3978,78409.54708,-27774.42335,-127872.1365,18879.12551,194650.9903,7368.517829,-279197.6607;
0,0,0,0,192,73.07564879,-1135.312342,-508.5655728,3706.949976,1946.428626,-9020.436512,-5497.089494,18315.25514,12841.39554,-32819.98602,-26305.72752,53592.96081,48907.83539,-81344.97478,-84369.59991,116249.2281,137093.641,-157744.2065,-212101.4947;
0,0,0,0,192,26.52487642,-1149.801347,-185.5323873,3822.418606,714.8963246,-9523.125445,-2036.182875,19914.17359,4805.440196,-36987.23947,-9962.723932,63039.66842,18780.08487,-100646.6018,-32907.74918,152629.087,54418.22672,-222018.2854,-85848.08848;
0,0,0,0,192,2.959359616,-1151.972632,-20.71532046,3839.781056,79.90093794,-9599.042127,-227.8620289,20156.93483,538.572741,-37623.95402,-1118.549352,64493.6094,2112.7619,-103642.0699,-3710.543262,158327.7533,6151.495274,-232190.8611,-9731.39151;
1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0;
0,0,4,0,-16,0,36,0,-64,0,100,0,-144,0,196,0,-256,0,324,0,-400,0,484,0;
0,0,0,24,192,840,2688,7056,16128,33264,63360,113256,192192,312312,489216,742560,1096704,1581408,2232576,3093048,4213440,5653032,7480704,9775920;
0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,441,484,529]
S=[1,0.998458667,0.993839419,0.986156496,0.975433581,0.96170373,0.945009268,0.925401657,0.902941342,0.87769756,0.84974813,0.819179209,0.786085032,0.750567618,0.712736454,0.672708162,0.630606134,0.586560159,0.540706014,0.493185053,0.444143767,0.393733335,0.342109153,0.289430364;
1,0.98618496,0.945121551,0.877944359,0.786509494,0.673343309,0.541572595,0.394838187,0.237194368,0.07299685,-0.093217576,-0.256856394,-0.413398249,-0.558517877,-0.688205612,-0.798878172,-0.887477663,-0.951556077,-0.98934292,-0.999794139,-0.982620967,-0.938297899,-0.868049586,-0.773816993;
1,0.961939766,0.850656228,0.67462034,0.447232036,0.18580022,-0.089774795,-0.35851611,-0.599967012,-0.795748145,-0.930956556,-0.99530012,-0.983880972,-0.897568346,-0.742932397,-0.531744087,-0.280079168,-0.007094493,0.266430219,0.519674138,0.733360219,0.891222577,0.981244656,0.996573933;
1,0.926320082,0.716137789,0.400425549,0.025706666,-0.352800347,-0.679318759,-0.90573287,-0.998678335,-0.944458724,-0.751063831,-0.446992295,-0.077052048,0.304242576,0.640704064,0.882751506,0.994716832,0.960100849,0.784004562,0.492377492,0.128193756,-0.254880591,-0.600395776,-0.857436738;
1,0.880202983,0.549514582,0.087165765,-0.396067449,-0.784405265,-0.984804259,-0.949250027,-0.686261152,-0.258848199,0.230583238,0.664768308,0.939678856,0.989447956,0.802151229,0.422663852,-0.058091262,-0.524928056,-0.86599522,-0.999575095,-0.89366274,-0.573634124,-0.116166194,0.369134463;
1,0.824724024,0.360339432,-0.230362851,-0.740310987,-0.990741662,-0.893865914,-0.483643725,0.096120716,0.642189852,0.963138082,0.946456378,0.597992543,0.039901255,-0.532177495,-0.917700386,-0.981521616,-0.701268527,-0.175184388,0.412310981,0.85526993,0.998412337,0.79155935,0.307223688;
1,0.761249282,0.15900094,-0.51917058,-0.949437402,-0.926346503,-0.460923818,0.224590651,0.802862762,0.997766752,0.716235686,0.092701052,-0.575098468,-0.968287643,-0.899118079,-0.400618342,0.289177228,0.840890257,0.991076981,0.668023024,0.025987114,-0.62845768,-0.98281303,-0.867873748;
1,0.691341716,-0.044093263,-0.75230874,-0.996111568,-0.624998222,0.131936882,0.807425162,0.984476513,0.553794202,-0.218754445,-0.856262349,-0.965185319,-0.4782834,0.303870785,0.8984405,0.93838801,0.399053054,-0.386623964,-0.933631603,-0.904292986,-0.316719326,0.46637042,0.96156198;
1,0.616722682,-0.239306267,-0.911893888,-0.885465021,-0.180278837,0.663100925,0.998177599,0.568096607,-0.297461473,-0.934999082,-0.855808809,-0.120594327,0.707062296,0.992717038,0.517399932,-0.354532491,-0.954696389,-0.823033344,-0.060470273,0.748446566,0.98363822,0.464817436,-0.410311308;
1,0.539229548,-0.418462989,-0.990524765,-0.649777453,0.289766361,0.96227862,0.74801177,-0.155578523,-0.915796843,-0.832070912,0.0184424,0.851960286,0.90036192,0.119043216,-0.771978681,-0.951590646,-0.254272907,0.677367717,0.984786282,0.384684007,-0.569920316,-0.999319756,-0.507805164;
1,0.460770452,-0.575381181,-0.991007746,-0.337872993,0.679643962,0.964192705,0.208899055,-0.771683681,-0.920037132,-0.07616817,0.849845048,0.859335144,-0.057932562,-0.91272237,-0.783178435,0.190991406,0.959184828,0.692936648,-0.320615363,-0.98839682,-0.590232736,0.444473211,0.99983298;
1,0.383277318,-0.706196995,-0.924615899,-0.002571609,0.92264462,0.70982912,-0.378521817,-0.999986774,-0.38802268,0.702546189,0.926562719,0.007714758,-0.920648935,-0.713442468,0.373756304,0.999947095,0.392757778,-0.698876799,-0.928485029,-0.012857704,0.918628896,0.717036943,-0.368980903;
1,0.308658284,-0.809460128,-0.808351431,0.310451397,0.999998222,0.306864073,-0.810565945,-0.807239861,0.312243405,0.999992888,0.305068772,-0.811668881,-0.80612542,0.314034304,0.999983998,0.303272386,-0.81276893,-0.805008112,0.315824085,0.999971552,0.301474921,-0.813866089,-0.803887941;
1,0.238750718,-0.88599619,-0.66181517,0.569978496,0.93398072,-0.124001362,-0.993191548,-0.350249028,0.825947135,0.74463997,-0.47038048,-0.969247324,0.007563492,0.972858903,0.456978031,-0.754651237,-0.81732508,0.364377338,0.991315782,0.10897737,-0.939278931,-0.557484408,0.673079326;
1,0.175275976,-0.938556665,-0.504288846,0.761777225,0.771331339,-0.491385519,-0.943587492,0.160609082,0.999889319,0.18990407,-0.933318077,-0.517080544,0.752054483,0.78071471,-0.478373418,-0.948409446,0.145906635,0.999557301,0.204490127,-0.927872888,-0.529757779,0.742165265,0.789925261;
1,0.119797017,-0.971297349,-0.352514068,0.886837082,0.564994942,-0.751467664,-0.745042111,0.572960019,0.882319914,-0.361561431,-0.968947876,0.1294073,0.999953093,0.110175495,-0.973555702,-0.343433634,0.891271052,0.556976861,-0.757822719,-0.738546663,0.580871344,0.877719972,-0.370574875;
1,0.073679918,-0.989142539,-0.2194398,0.956805927,0.360434564,-0.903692348,-0.49360252,0.830955162,0.616051936,-0.74017385,-0.725123833,0.633319721,0.818449723,-0.512713105,-0.894003042,0.380972963,0.950143155,-0.240960024,-0.985650985,0.095714657,0.999755481,0.051609146,-0.992150366;
1,0.038060234,-0.997102837,-0.113960168,0.988428136,0.18919978,-0.97402616,-0.263343106,0.95398036,0.335960537,-0.928406887,-0.406631304,0.897453922,0.474945916,-0.861300817,-0.540508536,0.820157054,0.602939275,-0.774261035,-0.661876387,0.723878695,0.716978371,-0.669301966,-0.76792595;
1,0.01381504,-0.999618289,-0.041434573,0.998473449,0.069022474,-0.996566352,-0.096557681,0.993898456,0.124019175,-0.990471796,-0.151385989,0.986288989,0.178637233,-0.981353228,-0.2057521,0.975668281,0.232709893,-0.969238489,-0.259490029,0.962068758,0.286072066,-0.954164565,-0.312435708;
1,0.001541333,-0.999995249,-0.004623985,0.999980994,0.007706592,-0.999957238,-0.010789127,0.999923978,0.013871559,-0.999881217,-0.016953859,0.999828954,0.020035998,-0.999767189,-0.023117946,0.999695925,0.026199675,-0.99961516,-0.029281155,0.999524896,0.032362357,-0.999425133,-0.035443251;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Results from eig(H,S):
-10.4013941701241 + 0i
495.8709816739 + 0i
-2075.89359089271 + 0i
3810.96559828315 + 0i
-12007.5792049748 - 7859.80373595807i
-12007.5792049748 + 7859.80373595807i
13744.8803145627 - 6829.57196964173i
13744.8803145627 + 6829.57196964173i
40714.6215488508 + 0i
161777.282995074 + 0i
-222054.135160397 + 0i
456554.085296176 + 0i
1046529.30310225 + 0i
2209556.44199227 + 0i
-3698516.26538781 + 0i
5938712.03152599 + 0i
29139261.3696759 + 0i
35187640.9660181 + 0i
-106153683.549455 + 0i
625134760.07866 + 0i
Inf + 0i
Inf + 0i
Inf + 0i
Inf + 0i
Resluts from putting determinant equal to 0:
6.0880681896251522577558901777469
493.13352335963732050050918987025
3805.0426185157246029406709075097
14617.451723278368450735731815741
39943.815388339366263101056654306
89135.406154470667286843490819588
173881.32991449447500370097212608
308208.37416682144561534408214656
508470.65137071189157395633863007
793718.91013854156465411829146852
1184484.6868564064238468530882583
1708985.9187321214627561917325303
2400030.5803698046017748760892131
3509269.6989698602635588940827738
6117137.3935227069102232614222001
11673551.342361595565898213914818
30121894.392585463384868409705274
104001718.25765847906945083161619
953411363.34772056816450115047618
2832353346.2556813059459515513392
The problem is that both of the approaches are giving different eigenvalues. The second method(determinant one) gives correct results as they match with the values present in the research paper that I'm trying to implement. So, I have the following questions:
Why is eig(H,S) not giving correct eigenvalues?
Evaluating the determinant involves symbolic computation and the size of my matrices could be as large as 100x100 and this takes very long for MATLAB to solve. Is there any efficient way to evaluate determinants of large(non-sparse) symbolic matrices?
Related
Solving equations involving angles in matlab. Matrix or linsolve way
I cant get matlab to output an answer for me when I do x=A^-1*b or linsolve (A,b) I have four equations and 4 variables to solve. It involves sin and cos. ra=.15; r1=.15;r2=.1;rb=.15; //Radius syms Wa Wb %weight W1=45;W2=90; syms tA tB %theta t1=90;t2=0; aA=.03;a1=.18;a2=.33;aB=.43; %radius %Trying to solve for Wa,Wb,tA,tB mrcos=Wa*ra*cos(tA) + W1*r1*cos(t1) + W2*r2*cos(t2) + Wb*rb*cos(tB)==0; %mrcos mrsin=Wa*ra*sin(tA) + W1*r1*sin(t1) + W2*r2*sin(t2) + Wb*rb*sin(tB)==0; %mrsin macos=Wa*aA*cos(tA) + W1*a1*cos(t1) + W2*a2*cos(t2) + Wb*aB*cos(tB)==0; %macos masin=Wa*aA*sin(tA) + W1*a1*sin(t1) + W2*a2*sin(t2) + Wb*aB*sin(tB)==0; %masin A=[Wa*ra*cos(tA) W1*r1*cos(t1) W2*r2*cos(t2) Wb*rb*cos(tB); Wa*ra*sin(tA) W1*r1*sin(t1) W2*r2*sin(t2) Wb*rb*sin(tB); Wa*aA*cos(tA) W1*a1*cos(t1) W2*a2*cos(t2) Wb*aB*cos(tB); Wa*aA*sin(tA) W1*a1*sin(t1) W2*a2*sin(t2) Wb*aB*sin(tB)]; b=[0 0 0 0]'; x=inv(A)*b it just gives me the following when im trying to solve for Wa,Wb,tA,tB x= [0 0 0 0] im expecting not these values... ik they arent 0
Intersection of two rotated polynomials
I am currently trying to find the intersections points of two rotated polynomial 2nd degree (so also called parabolic). I am able to calculate the intersection points with no rotations, but not with one. My current code is based on Code or formula for intersection of two parabolas in any rotation syms t1 t2 % a1 b1 c1 are coefficients of the first polynomial % a2 b2 c2 of the second one % First polynomial equation fax = a1*t1.^2 + b1*t1 + c1; fay = t1; fax1 = fax*cos(w1) - sin(w1)*fay; fay1 = +fax*sin(w1) + cos(w1)*fay; % Second polynomial equation fbx = a2*t2.^2 + b2*t2+ c2; fby = t2; fbx1 = fbx*cos(w2) - sin(w2)*fby; fby1 = fbx*sin(w2) + cos(w2)*fby; [solT1 solT2] = solve([fbx1-fax1,fby1-fay1],[t1 t2],'MaxDegree', 4); double(solT1) double(solT2) But the solve function does not return equal values for x/y equations. Can somebody help me, where do I have my failure? Output: >> double(solT1) ans = -35970.3949972882 + 0i -547.958594347212 + 0i 45277.2230289302 + 73433.2725463157i 45277.2230289302 - 73433.2725463157i >> double(solT2) ans = -43312.4016357418 + 0i -123.972586439179 + 0i 87780.3324792941 - 89532.7369678429i 87780.3324792941 + 89532.7369678429i
How can I get MATLAB to numerically solve a particularly nasty system of equations?
I have four parameters, t1,t2, theta1, and theta2. I want to find a solution (there can potentially be infinitely many) to the following system of equations: t1*cos(theta1) + t2*cos(theta2) + 2*t1*t2*sin(theta1 + theta2) = t1*sin(theta1) + t2*sin(theta2) + 2*t1*t2*cos(theta1 + theta2) + 1 t1*cos(theta1) + t2*cos(theta2) + t1*sin(theta1) + t2*sin(theta2) = 2*t1*t2*sin(theta1 + theta2) + 2*t1*t2*cos(theta1 + theta2) + 1 2*t1^2*t2^2 + sin(theta1)*t1*t2^2 + sin(theta1 + theta2)*t1*t2 + 1 = sin(theta2)*t1^2*t2 + t1^2 + sin(theta1)*t1 + t2^2 Since there are more parameters than equations, we have to impose further restrictions to identify a specific solution to this system. Right now I don't really care which solution is picked, as long as it isn't trivial (like all the variables equaling zero). My current method is to set the third equation to 0.5, solving for t1 and t2 in terms of theta1 and theta2, and substituting these expressions into the first two equations to solve for theta1 and theta2. However, MATLAB is trying to do this symbolically, which is extremely time-consuming. Is there a way I can get some approximate solutions to this system? I can't exactly plot the surfaces represented by these equations and look at their intersection, because each side of the equations involves more than two parameters, which means it can't be visualized in three dimensions.
You can use fsolve to do this. First, you need to create anonymous functions for the residuals of the three equations. I'm going to create a vector x where x = [t1; t2; theta1; theta2]. That makes the residuals: r1 = #(x) x(1)*cos(x(3)) + x(2)*cos(x(4)) + 2*x(1)*x(2)*sin(x(3) + x(4)) - (x(1)*sin(x(3)) + x(2)*sin(x(4)) + 2*x(1)*x(2)*cos(x(3) + x(4)) + 1); r2 = #(x) x(1)*cos(x(3)) + x(2)*cos(x(4)) + x(1)*sin(x(3)) + x(2)*sin(x(4)) - (2*x(1)*x(2)*sin(x(3) + x(4)) + 2*x(1)*x(2)*cos(x(3) + x(4)) + 1); r3 = #(x) 2*x(1)^2*x(2)^2 + sin(x(3))*x(1)*x(2)^2 + sin(x(3) + x(4))*x(1)*x(2) + 1 - (sin(x(4))*x(1)^2*x(2) + x(1)^2 + sin(x(3))*x(1) + x(2)^2); Then, we need to make a single function that is a vector of those three residuals, since fsolve tries to get this vector to be zero: r = #(x) [r1(x); r2(x); r3(x)] Now, we call fsolve. I picked an arbitrary starting point: >> [x, fval, exitflag] = fsolve(r, [0.5,0.5,pi/4,pi/4]) Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead. > In fsolve at 287 Equation solved. fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient. <stopping criteria details> x = 0.9654 0.5182 0.7363 0.7344 fval = 1.0e-10 * -0.0090 0.2743 -0.0181 exitflag = 1 You can ignore the warning. x is the four values you were looking for. fval is the value of the residuals. exitFlag == 1 means we found a root.
Contour plot in matlab - takes forever
I am trying do a contour plot in matlab. However, the syntax seems to be correct but the matlab is taking forever to plot this as the matrix could be really large. Please suggest what can I do about this. Below is my code: s = 10000000; eta_gamma = zeros(s/10000); for g1= 1:10000:s for g2 = 1:10000:s eta_gamma(g1,g2) = floor((1000000000 - g1 - g2)/ (200000*(1 + floor(-0.001 + 20000*(0.001 + (0.1 + 0.9/ (1 + (-1000000 + 5000000* lambertw(power(exp(1), 0.2 + g1/5.E6)/5.))/1.E6))/ 100.))) + 75000*(1 + floor(-0.001 + 20000*(0.002 + (0.2 + 0.8/ (1 + (-8000000 + 4000000* lambertw(2* power(exp(1),2 + g2/4.E6)))/8.E6)) /200.))))); end end figure contour(eta_gamma)
It seems that the bottleneck is because of the two heavy nested loops there. The solution is of course vectorization with the intention to remove those two loops. One of the best tools for vectorization, bsxfun could be used here. The final vectorized implementation listed next ran in 1.323403 seconds at my end, whereas the original nested loopy version was taking forever and using up a lot of memory. Here's the code - %// Input parameter s = 10000000; %// Define 1D arrays corresponding to each nested loop G1 = 1:10000:s; G2 = 1:10000:s; %// Perform the calculations in a vectorized manner in three parts: %// Part1: Do vectorized "1000000000 - g1 - g2" p1 = 1000000000 - bsxfun(#plus,G1,G2.'); %//' %// Part2: Do vectorized operations for everything involving G1 (nested loop-I) p2 = 200000*(1 + floor(-0.001 + 20000*(0.001 + (0.1 + 0.9./ (1 + (-1000000 + ... 5000000* lambertw(power(exp(1), 0.2 + G1/5.E6)/5.))./1.E6))/ 100.))); %// Part3: Do vectorized operations for everything involving G2 (nested loop-II) p3 = 75000*(1 + floor(-0.001 + 20000*(0.002 + (0.2 + 0.8./(1 + (-8000000 + ... 4000000* lambertw(2* power(exp(1),2 + G2/4.E6)))/8.E6)) /200.))); %// Finally combine all parts into a 2D array output, which would be eta_gamma eta_gamma_vectorized = floor(p1./bsxfun(#plus,p2,p3.')); %//' %// Plot results figure, contour(eta_gamma_vectorized) Here's the plot result -
limitations of non linear multivariant equation solvers in matlab
I have a system of non-linear multivariate equations. I am only interested in the roots of the system in an interval of each variable. For example, F = #(x,y,z) [... sin((x*y)/100 + (y*z)/5)/10 + sin((y*z)/10)/10 + (y*cos((y*z)/10)*(x/10 + z))/100 + (y*cos((x*y)/100 + (y*z)/5)*(x/5 + z))/50 = 0 (z*cos((y*z)/10)*(x/10 + z))/100 + (cos((x*y)/100 + (y*z)/5)*(x/5 + z)*(x/100 + z/5))/10 = 0 sin((x*y)/100 + (y*z)/5)/50 + sin((y*z)/10)/100 + (y*cos((x*y)/100 + (y*z)/5)*(x/5 + z))/1000 = 0 ]; and I am only interested in the interval of x in [0 10] and y in [-10 10] and z in [-5, 10]. My question is: is there any method that can find 'all' the roots in these interval? is there any solution that can tell me only number of roots in these intervals ? If there is no general solution for question 1 and 2 (which I think there is not), then under what condition I can find all the roots (e.x. linear equations or polynomial are clearly solvable, but I want something more general such as Trigonometric equations).