How to write function for two variables
10 views (last 30 days)
Show older comments
I am trying to write down the function to predict "y" having two independent variables "x1 & x2". Here is my code for the function;
function y=Project_func(beta0,x1,x2)
y=100./(1+exp((-beta0(1).*(-2.4-(39.7*(1+x1).^(-2.8))))+(beta0(2).*(-2.4-(39.7*(1+x1).^(-2.8))).*log10(100.*x2))));
end;
but once I run the code it does not spit the y values as desired because I have predicted values taken from the excel. I want to solve it in the Matlab. Here are the equations. C1 & C2 are parameters having intial guess.

7 Comments
Accepted Answer
dpb
on 22 Feb 2023
I'd approach writing the functional something more like--
function y=Y(C,x1,x2)
% Magic function Y=fn(C, x1, x2) from unknown source
% C is 2-vector of C1, C2 per Eqn 1
C1=C(1); C2=C(2); % convenience in writing expression w/o subscripts
C2S=@(x) -2.40874-39.748*(1+x).^-2.856; % define C2* as anonymous function(x)
y=100./(1+exp(-C1.*C2S(x1)+C2.*C2S(x1).*log10(100*x2))); % the function (x1,x2) for input C
end;
If we had the experimental or other data, be interesting to see how well it would fit...but, we're pretty much hamstrung at this point.
0 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!