필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
shaucha
shaucha 2014년 12월 24일
편집: Mike Hosea 2014년 12월 25일
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에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by