how to read a table created in matlab by taking integral calculations ?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
shaucha
el 24 de Dic. de 2014
Editada: Mike Hosea
el 25 de Dic. de 2014
I want to use the y vale corresponding to the given x value from the table (my current table has 1000 values with 10-4 decimal points so I use :
load question_table.mat
eta_p = %assign a value
F12_p=find( (eta <eta_p+0.01) & (eta > eta_p-0.01), 1, 'first' )
what is missing ?
Here is how I have created the table, run this program.
i = 1;
etaspan = -500:0.001:500;
y = zeros(length(etaspan),1);
f = @(x,eta) (x.^(1/2))./(1+exp(x-eta));
for eta = etaspan
g = @(x) f(x,eta);
y(i) = integral(g,0,500);
i = i + 1;
end
f=y
eta=etaspan
save question_table.mat eta f
0 comentarios
Respuesta aceptada
Mike Hosea
el 25 de Dic. de 2014
Editada: Mike Hosea
el 25 de Dic. de 2014
I think what you might be missing is that FIND is returning an index, so the eta value you seek is eta(F12_p). But I didn't really try your approach. Here's how I might have done it.
etaspan = -500:0.001:500;
f = @(x) (x.^(1/2))./(1+exp(x-etaspan)); % A vector-valued function.
y = integral(f,0,500,'ArrayValued',true); % Calculate the integrals in one call.
% If y is already sorted, just use ys = y and idx = 1:length(etaspan).
% Note that we do assume that the y values are unique.
[ys,idx] = sort(y);
% Use the table to look up the nearest eta value given a y value.
findeta = @(y)etaspan(interp1(ys,idx,y,'nearest','extrap'));
FIND uses a linear search. INTERP1 uses a binary search, which should be faster. Now if you didn't want to use the table, fzero might work.
f = @(x,eta)(x.^(1/2))./(1+exp(x - eta));
findeta = @(y)fzero(@(eta)integral(@(x)f(x,eta),0,500) - y,0);
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!