solve nonlinear equations + numerical integration
Show older comments
Hi, I just have no idea how to do this.. I have code
x = [1.4334 1.46 0.1; 1.435 1.46 0.1];
t = 0.1:0.1:0.6;
for i=1:length(x)
z(i) = trapz(t,normcdf(((log(x(i,1)./x(i,2))+t.*x(i,3).^2)),0,1));
end
But I do not know what x(:,3) is, above I have just used x(1,3)=x(2,3)=0.1 but that is just a guess! I do now what the above function z(i) should be equal to for each 'i', z(1)=0.0213 and z(2)=0.0222 and I want to solve to find a x(1,3)=x(2,3). I do not want to find a single numeric value x(1,3)=x(2,3) that will not solve the equations exactly but just the best x(1,3)=x(2,3) that fits both equations in terms of mean squared error. I do not want two values x(1,3) and x(2,3) that are different, I am not trying to solve each equation individual but a x(.,3) that solves them all best in terms of mse.
Heres my code
x = [1.4334 1.46 0.1; 1.435 1.46 0.1];
y = [0.0213, 0.0222]
t = 0.1:0.1:0.6;
xdata = x(:,1); ydata = y;
for i=1:length(x)
z(i) = trapz(t,normcdf(((log(x(i,1)./x(i,2))+t.*c.^2)),0,1));;
end
c = 0.1; %initial guess for x(:,3)
cfit = nlinfit(xdata,ydata,z,c)
which does not work. I just dont understand how to simultaneously solve a set of equations when there is numerical integration involved.
Any ideas?
3 Comments
Walter Roberson
on 25 Apr 2012
It is not clear how this question differs from your earlier questions http://www.mathworks.com/matlabcentral/answers/36536-numerical-integration and http://www.mathworks.com/matlabcentral/answers/36534-solve-nonlinear-equations-that-have-numerical-integration ?
john birt
on 25 Apr 2012
john birt
on 26 Apr 2012
Accepted Answer
More Answers (2)
Walter Roberson
on 25 Apr 2012
Looks to me like this code would be appropriate:
lnx12 = log(x(:,1) ./ x(:,2));
cguess = 0.1;
C = zeros(1,length(x));
for i=1:length(x)
C(i) = fzero( @(c) z(i) - trapz(t, normcdf(lnx12(i)+t.*c.^2), 0, 1), cguess);
end
cfit = nlinfit(xdata,ydata,z,C);
Richard Brown
on 25 Apr 2012
Final answer: your equations have no solution
t = 0.1:0.1:0.6;
z = [0.0213; 0.0222];
x = [1.4334 1.46; 1.435 1.46];
f1 = @(y) trapz(t, normcdf(log(x(1,1)/x(1,2) + t*y^2),0,1))-z(1)
f2 = @(y) trapz(t, normcdf(log(x(2,1)/x(2,2) + t*y^2),0,1))-z(2)
Now plot both functions - neither has a zero
fplot(f1, [-10, 10])
hold on
fplot(f2, [-10, 10])
3 Comments
john birt
on 25 Apr 2012
Richard Brown
on 25 Apr 2012
Cool - use |fzero| individually for each equation from *this* example, not my previous answer
john birt
on 26 Apr 2012
Categories
Find more on Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!