필터 지우기
필터 지우기

How to increase the number of decimals of the values stored in a matrix

조회 수: 2 (최근 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?

채택된 답변

Walter Roberson
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
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by