Optimizing my nonlinear system of equations solving code
Show older comments
Hi,
I wrote some code to solve some non linear system of equation.
The number of equation vary (I want the highest number as possible for precision)
First I did it for 10 equation explicitly, then I did it for i equations and my code is working until i is around 20 to 25.
close all
clear all
clc
%declare number of type
ntype=25
%I declare the function I will solve
t=sym('type',[1 ntype]);
w=sym('wack',[1 ntype]);
fct=sym('n',[1 ntype]);
fct2=sym('m',[ntype ntype]);
% I create my type between 0 and 1.
type = 1:ntype;
type = type/ntype;
n = length(type)
type = type';
dm1 = diag(ones(1,n));
dm2 = diag(ones(1,n-1),-1);
dm3 = diag(ones(1,n-1),1);
matchset = dm1+dm2+dm3;
type=sort(type,'descend');
prod =type*type';
matchnom = t*matchset;
for ii = 1:ntype
t(ii)-(0.05*(1/n)/((0.05+5*(matchnom(ii)))))
fct(ii)=ans
end
assume(t>0);
v1=vpasolve(fct,t);
The 6 last line are, I define all my functions and place them in a vector with a loop and then on the last line I solve them.
My program continue after that and I use vpasolve on a more complicated non lin system, but i have no problem to solve that one. This solve is exponentielly longer , for 10 eq its 2 sec, 15 eq 6 sec , 20 eq 6 min , 22 eq 12 min, 25 eq it bugs and give me these warnings, and the values are not calculated:
Warning: Solutions might be lost. [solvelib::allvalues_warning]
Warning: Could not extract individual solutions. Returning a MuPAD set object.
> In sym.vpasolve>assignOutputs at 145
In sym.vpasolve at 118
I think vpasolve compute alot of solution but i need the only one where every variable>0, when i was doing it explicitly it gave me 12 answer for 10 type and 72 for 25 type, meaning 12 solution for the 10 variable versus 72 solution for 25 variable. So as the numb of equation/variables increase, the number of solution increase alot.
vpasolve seems to give me too many answer, I only want the answer where every variable is >0 and there will be only one set of value like that.
I'm fairly new, my code might seem fairly bad because I made it all by myself by looking at many answer on forums . It is working but not at the degree I would like to.
Any help would be greatly appreciated.
Jerôme
Answers (1)
jerome
on 10 Nov 2014
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!