Hi , I am very new to Matlab, so I am facing some problems. Would u mind give me a bit of help?
1 次查看(过去 30 天)
显示 更早的评论
My problem is that i cant run this function on curve fitting toolbox
The script i want to run:
%x,y,z are matrices of same size
function z=fc1(x,y,theta)
for i=1:size(x)
z=((1-x)^theta+(1-y)^theta-1)^(-1/theta)+x+y-1;
end
end
How can i run it into curve fitting so i can reach theta value?
0 个评论
回答(1 个)
Javier Bastante
2016-3-16
Function solve can help you here. Your input in that function can be symbolic variables or string variables, so thats what we are going to do. Transform each value of your matrices into a string and get each value of theta, your OUTPUT value, that's why your first line must change:
function theta=fc1(x,y,z)
%x,y,z are matrices of same size and must be your INPUT values
theta=[]; %We must initialize the variable
%Size gives you two values. Length is used for rows and columns
%For two dimensional arrays use a "for" for columns and another one for rows
for i=1:length(x),
solution=solve([num2str(z(i)) '=((1-' num2str(x(i)) ')^theta+(1-' num2str(y(i)) ')^theta-1)^(-1/theta)+' num2str(x(i)) '+' num2str(y(i)) '-1','theta');
solution=double(solution); %Just to get the solution as a number, and not as symbolic
theta(i)=solution; %Finally we introduce the obtained value on its place
end
end
Hope it works. Regards
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!