Info
This question is closed. Reopen it to edit or answer.
implementing a function that contains an integral
2 views (last 30 days)
Show older comments
good morning, i have a litle problem here, wich is: i need to make a code that assure the optimization of a fonction, by finding the optimums parameters that approach the experimental values to the theoretical function , the problem is that the téorical function contains an integral, and i couldn't write it correctly, so it shows a wrong ansers, here is the code, please hepl me to find where i'm i wrong
function main
global ti yi
ti = [3 12 24 48 168];
yi = [0.6 0.7 1 1.2 1.4];
a0 = [10 0.4];
format long
asol = fminsearch ( @F, a0)
plot (ti, yi, '*', ti, f(asol, ti))
function y = f(a,t)
myfun = inline('v.*(((a(1)-1).*(a(2)*1400*t))+((-16.7.*v).^(1-a(1)))).^(1/(1-a(1)))','a','t','v');
for k = 1:length(t)
fc(k) =quad(@(v)myfun(a,t(k),v), -1.8, 1.8);
end
y=2.9-0.035.*fc;
function out = F(a)
global ti yi
out = sum ( (yi - f(a,ti)).^2 );
0 Comments
Answers (2)
Mike Hosea
on 3 Jun 2011
Well, as an aside, you shouldn't need to use 'inline', rather
myfun = @(a,t,v)(blah, blah, blah)
Secondly, I don't know what is going on, but I'm wondering whether you expected to generate complex numbers. Maybe there's an error in myfun. -- Mike
0 Comments
eya
on 3 Jun 2011
1 Comment
Mike Hosea
on 4 Jun 2011
My point is that if you integrate that function as specified, it gives you complex results. Suppose a(1) = 10.5, then the term (-16.7*v)^(1-a(1)) = (-16.7*v)^(-9.5). This term has a singularity at v=0, and furthermore, the term is calculates as exp(-9.5*log(-16.7*v)), so for positive v this involves log of a negative number.
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!