How to use "format long" in fmincon?

I need Matlab give the answers x1 and x2 decimal format with 15 digits after the decimal point.
% Função objetivo: Função de Rosenbrock
objetivo=@(x) 100*(x(2)-x(1)^2)^2+(1-x(1))^2;
% Estimativa inicial
x0 = [0.5,0];
% Imprime o objetivo inicial
disp(['Objetivo inicial:' num2str(objetivo(x0))])
% Restrições lineares
% Desigualdade ("<=")
A = [1,2]; % Matriz contendo os coeficientes da restrição de desigualdade
b = [1]; % Vetor contendo o valor a ser satisfeito da desigualdade
% Igualdade ("=")
Aeq = [2,1]; % Matriz contendo os coeficientes da restrição de igualdade
beq = [1]; % Vetor contendo o valor a ser satisfeito da igualdade
% Otimização com fmincon
x = fmincon(objetivo,x0,A,b,Aeq,beq);
% Imprime o objetivo final
disp(['Objetivo final:' num2str(objetivo(x))])
% Imprime solução
disp('Solução')
disp(['x1 = ' num2str(x(1))])
disp(['x2 = ' num2str(x(2))])

 Respuesta aceptada

Steven Lord
Steven Lord el 1 de Sept. de 2020
Specify the second input (either precision or formatSpec) in your calls to num2str as shown on its documentation page.
doc num2str

2 comentarios

Elizabeth Valente
Elizabeth Valente el 1 de Sept. de 2020
Editada: Elizabeth Valente el 1 de Sept. de 2020
Unrecognized function or variable 'precision'.
Error in rosenbrock (line 27)
disp(['x1 = ' num2str(x(1), precision)])
Sorry, I dind't understand.
Where I specify "format long"?
You don't. format will not affect what num2str returns nor how the text that it returns is displayed.
Consider this example:
disp(num2str(pi))
disp(num2str(pi, 2))
disp(num2str(pi, 12))
Adapt these to your needs. See the examples on the documentation page for more information about the formatSpec input argument if you think you need the additional flexibility it can provide.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Preguntada:

el 1 de Sept. de 2020

Comentada:

el 1 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by