how to read a table created in matlab by taking integral calculations ?

4 次查看(过去 30 天)
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

采纳的回答

Mike Hosea
Mike Hosea 2014-12-25
编辑:Mike Hosea 2014-12-25
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 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by