How to increase the number of decimals of the values stored in a matrix
6 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone. I wish to rephrase the question I asked last week.
I used the code below to obtain the minimum solutions of a function F and the corresponding values of F. The solution x is a five component vector i.e. x = [x1;x2;x3;x4;x5] and fvals the corresponding minimum of F at each solution. Next I stored x and fvals respectively as the first and second column of a matrix M and lastly I stored the lowest minimum at each j and the corresponding solution in a matrix P.
This is my code
for j = 1:1:numz
z=zvec(j);
% using all possible initial values by iterating over x0
for k=0:1:3
for l=0:1:3
for m=0:1:3
for n=0:1:3
for p=0:1:3
x0=[k*pi/3;l*pi/3;m*pi/3;n*pi/3;p*pi/3];
% calling the function
[x,fvals]=fmincon(@(x) F(x,z))...
,x0, [], [], [], [], -pi*ones(5,1), pi*ones(5,1));
% storing the results as a matrix
M(position, 1)= {x};
M(position, 2) = {fvals)};
position = position+1;
end
end
end
end
end
%picking the lowest minimum for each j
[~, ind] = min([M{:,2}]);
P(j,:) = M(ind,:);
end
I have two problem:
1) I want fvals to be stored in M upto twenty (20) decimal place instead of the default four(4) decimal places. I have tried
format long , longG, fprint('%0.20f', fvals) but none worked.
2) In the last part I tried to pick the lowest value of F for each value of j and its corresponding x and store them in a matrix P but the system is degenerate i.e. many x give the same solution or fvals. The code I wrote returns the first minimum for each j but I wish to pick another minimum for which x5 > 0 and x3 >0.
How do I solve this two problems?
0 件のコメント
採用された回答
Walter Roberson
2014 年 2 月 13 日
MATLAB cannot calculate numerically to more than 53 bits of precision (relative error of about 1E-16)
You can use the Symbolic Toolbox if you have it, or you could attempt to use one of John D'Errico's variable precision packages from the File Exchange.
3 件のコメント
Shameer Parmar
2014 年 12 月 8 日
Hello Oladunjoye,
Can you please tell me how you get to achieve the value upto 20 decimal places? because the same concept I am using in my scripting but I am getting the values upto 16 decimal places only and after 16, it is rounding that values to zeroooooo
Thanks for your help.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!