error when using lsqnonlin to function containing fzero function
1 次查看(过去 30 天)
显示 更早的评论
I want to use lsqnonlin analysis to fit a model to two sets of data and obtain values of 4 variables. The function i created contains fzero function which only allows scalar values and i finally got the error 'operands to the || and && operators ust be convertible to logical scalar values. ' So is there any other method that can replace lsqnonlin to solve my problem? Or any corrections, changes to be made in my code to solve this with lsqnonlin? Thanks! Here's my function file and code.
function Result = myfunc1(a,p,G,m,fraction)
totalconcentration = 0.0000291;
n = 2;
K = exp(-((G + m * fraction)./(8.314*298)));
g_lb = 0;
g_ub = 0.9999;
g =[g_lb g_ub];
monomerconcentration = fzero(@denaturationfun,g);
function y = denaturationfun(x)
y = a.^(-1).*(((a.*x).^(n+1)).*(n.*a.*x-n-1)/((a.*x-1).^2)+a.*x/((a.*x-1).^2))-a.^(n-1).*((x^(n+1)).*(n.*x-n-1)/((x-1).^2))-K.*totalconcentration;
end
Result = p * (1- (monomerconcentration / ( K * totalconcentration )));
end
clc;
clear;
close all;
fractiondata = [0.1505 0.1546 0.1587 0.1628 0.1668 0.1708 0.1748 0.1787 0.1825 0.1864 0.1902 0.194 0.1977 0.2014 0.205 0.2087 0.2123];
DegreeofAggdata = [1 0.9087 0.8658 0.83453 0.79569 0.67979 0.62031 0.53043 0.39722 0.25888 0.15171 0.04759 0.00109 3.20E-04 0.00144 7.77E-04 0];
fun = @(x)DegreeofAggdata - myfunc1(x(1),x(2),x(3),x(4),fractiondata);
x0 = [0.01,0.9,-50000,100000];
lb = [0.00001,0.9,-100000,20000];
ub = [1,1.1,-10000,130000];
x = lsqnonlin(fun,x0,lb,ub);
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!