Matlab continues to run and wont stop. Is my solution to complicated?

Here is my code
syms x y
a= 13;
b= 5;
c=2;
d=5;
p = 4*(a+b+c+d);
f(x,y)= (p./((3*x+a).^2+(3*y+c).^2+(a+c)))...
-(2*p./((3*x-b).^2+(3*y+d).^2+(b+d)))...
-(3*p./((3*x+a).^2+(3*y-d).^2+(a+d)))...
+(4*p./((3*x-b).^2+(3*y-c).^2+(b+c)));
ezsurf(f,[-10,10])
title('My land');
xlabel('X- Axis');
ylabel('Y-Axis');
colormap(jet)
hold off
fx= diff(f,x);
fy=diff(f,y);
[a,b]= solve(fx,fy);
double([a,b])

Risposte (2)

Try doing this in your code;
fx = simplify(expand(diff(f,x)));
fy = simplify(expand(diff(f,x)));
I think in your code, the expression for fx is too complicated without the simplify(expand()) command. When I replaced that part, it was able to solve in a second or so.

3 Commenti

Unfortunately, not really. When you
[a,b] = solve(fx, fy)
after the simplify(expand)) then you get back the response
a = u
b = v
which is shorthand for
sol = solve([fx, fy], 'returnconditions', true);
in which case sol.parameters becomes u and v, and sol.conditions expresses all of the work of the equations:
3232051880960*v + u*(- 59049*v^11 + 7696053*v^10 + 8516178*v^9 + 198290916*v^8 + 525078288*v^7 + 38129616*v^6 + 30201424128*v^5 + 52493754240*v^4 + 459252951552*v^3 + 828235051776*v^2 + 1468880331264*v + 133528446976) + 1359872700160*v^2 + 951207955200*v^3 + 169992437184*v^4 + 114589320192*v^5 + 13985939520*v^6 + 7991822880*v^7 + 1041942204*v^8 + 332170308*v^9 + 40199247*v^10 + 6121413*v^11 + 531441*v^12 + 2708062269440 == 1594323*u^12 + (59049*v + 26847612)*u^11 + (7440174*v^2 + 31866777*v + 165599640)*u^10 + (295245*v^3 + 99694395*v^2 + 505603782*v + 485006616)*u^9 + (13286025*v^4 + 121345695*v^3 + 558426393*v^2 + 3611305620*v + 1366017696)*u^8 + (590490*v^5 + 130301460*v^4 + 1508295168*v^3 + 2237073552*v^2 + 13931388288*v + 6938244864)*u^7 + (10628820*v^6 + 166715010*v^5 + 641482092*v^4 + 8681812632*v^3 + 10473694632*v^2 + 24780630672*v + 19809183744)*u^6 + (590490*v^7 + 61214130*v^6 + 1491262812*v^5 + 2820836340*v^4 + 28942816320*v^3 + 50806762704*v^2 + 2403999648*v + 10675027584)*u^5 + (2657205*v^8 + 90738630*v^7 + 229884318*v^6 + 6197538096*v^5 + 11252940228*v^4 + 67802167152*v^3 + 163437102000*v^2 + 57381994944*v - 24410921472)*u^4 + (295245*v^9 - 3936600*v^8 + 480055248*v^7 + 870478488*v^6 + 14486349744*v^5 + 23286118464*v^4 + 120922932672*v^3 + 210529217664*v^2 + 540627457536*v + 115004841984)*u^3 + (- 1062882*v^10 + 7381125*v^9 - 58970268*v^8 + 794860776*v^7 + 1103321088*v^6 + 9151784352*v^5 + 177250032*v^4 + 291665664*v^3 - 180827531136*v^2 + 507038485248*v + 574441932800)*u^2
which solves nothing in practical terms.
hey aquartis, did this actually work for you? because my matlab is still timing out when trying.
It worked. I used Matlab online. However as Walter commented, this might not be what you want.

Accedi per commentare.

If you try stepwise elimination of either fx or fy with respect to either x or y, you will get a solution involving the roots of a polynomial of order 12. With each of them being order 12, MATLAB has to work through 144 different roots -- but it cannot express them in full because there is not typically any closed form expression for any order above order 4. So this is not an easy equation to solve.
Unfortunately proceeding numerically does not work well in this case: the loss of precision that goes along with working with floating point numbers can result in somewhat negative values being calculated from fx^2+fy^2 even though algebraically that should not be possible.
You appear to be trying to calculate all of the extrema and inflections of f(x,y), including the complex ones.
If you are just looking for the global minima, then it is at about -4.34915949152492498, 1.72539721154691694

2 Commenti

so this mean it is essentially not possible to find the solution via matlab bc its too complex?

Accedi per commentare.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by