0
votes

I wanted to know a specific thing about Matlab fsolve technique. As shown in the code, there are two non-linear equations. I can normally solve them but I want to optimise the process. It is observed that there is a common term 2*x(1)^2 - 3*x(2)^3 in both of these equations. The question is, can I declare a separate term for the common part and use the fsolve(as in the commented part)? If yes, can anyone please tell me the way to do.

function f = sym4(x)    
f(1)= 8*x(1)^2 -12*x(1)^3 +x(1)*x(2)+ x(2)^2-1;
f(2)= 2*x(1)^3 - 3*x(1)^4 +x(2)-3;

% z = 2*x(1)^2 - 3*x(2)^3;
% 
% f(1)= 4*z + x(2)^2 + x(1)*x(2) -1;
% f(2)= x*z +x(2)-3;


end
1
Your question, algebra, and code don't match up. Look again closely and pay attention to the indexes. - horchler
Thanks, for clarifying the doubt. Ya, I changed x to x(1) and it worked normally. - Sumanth Mehatha

1 Answers

0
votes

Yes, you can use intermediate variables, which may be somewhat faster because the common term is only evaluated once. As horchler pointed out, you should check your indexes.