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?

답변 (1개)

Javier Bastante
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

카테고리

Help CenterFile Exchange에서 Curve Fitting Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by