Borrar filtros
Borrar filtros

How to save values in a specific position+stop output

1 visualización (últimos 30 días)
Maximilian Jatzkowski
Maximilian Jatzkowski el 2 de En. de 2019
Editada: madhan ravi el 7 de En. de 2019
I am using fzero to solve a non-linear function, and then using a for-loop to plot the function for different values of p.
volume=fzero(@(V) volume(V,P), fstart);
for P=5:1:15
Volume=fzero(@(V) volume(V,P),fstart);
end
P=P+1;
plot(Volym)
Several questions;
How do i stop the loop from displaying every value of 'Volume' in the command window? The ';' in the loop doesnt seem to stop this.
How do i get the Volume loop to store the values in a 1x10 double, starting with P=5 on the first and P=15 on the tenth? Currently, the loop saves the first 5 (for P=0 until P=4 as zeros, which makes the Volume expression a 1x15 double instead. So essentially i need a way to ignore the first 5 columns.

Respuestas (1)

madhan ravi
madhan ravi el 2 de En. de 2019
You need to upload your missing parts of your code to be debugged:
volume=fzero(@(V) volume(V,P), fstart);
P=5:15;
Volume=zeros(size(P)); % preallocate
for i=1:numel(P)
Volume(i)=fzero(@(V) volume(V,P(i)),fstart);
end
plot(Volym)
  4 comentarios
madhan ravi
madhan ravi el 2 de En. de 2019
Editada: madhan ravi el 2 de En. de 2019
P has only 11 points :
n=2;
a=1.360;
b=0.003183;
R=0.0821;
T=300;
P=5;
% fplot(@(V) volym(V,P),[0 0.1]);
fstart=0.1;
P=5:15; % if you want 15 points then try linspace(5,15,15)
Volume=zeros(size(P)); % preallocate
for i=1:numel(P)
Volume(i)=fzero(@(V) volym(V,P(i)),fstart); % function call
end
Volym=volym(Volume,P);
xx=linspace(P(1),P(end),1000);
yy=interp1(P,Volym,xx,'spline'); % for a smooth curve
plot(P,Volym,'o',xx,yy)
% axis([5 15 0.1 0.12])
title('Volume dependent on Pressure')
xlabel('Pressure')
ylabel('Volume')
function Volym=volym(V,P) % function definition
n=2;
a=1.360;
b=0.003183;
R=0.0821;
T=300;
Volym=(P+(a.*(n./V).^2)).*(V-(n.*b))-n.*R.*T;
end
The graph :
Note: I still have no idea what you are trying to do but clarify.
madhan ravi
madhan ravi el 7 de En. de 2019
Editada: madhan ravi el 7 de En. de 2019
If it’s what you were looking for make sure to accept the answer else let know.

Iniciar sesión para comentar.

Categorías

Más información sobre Elementary Math en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by