Using curve fitting with solve function

8 次查看(过去 30 天)
Using formula(curvefit) I can get the polynomial function of the curvefit to show in the command window.
I would like to use that polynomial equation togheter with a function handle, that comes from another function file, and pass them to a the solve function to solve for one of the two variables.
I_sc has variables x and y.
I_sc_max only has variable y (the same y as I_sc).
The second problem is that i want to use the solution (one of the solutions) from the solve function as a function handle.
Thanks for any help!
This code is my try at solving the problem but using the == sign doesn't work well with sfit.
Error:
Undefined function 'eq' for input arguments of type 'sfit'.
syms x y;
% Curve fit: poly23.
% formula(curvefit) shows the sfit uses variables x and y.
I_sc = curvefit; % sfit
I_sc_max = I_sc_max_function(); % function handle from other file. Variable y.
eqn = I_sc == I_sc_max; %<--- ERROR
S = solve( eqn, x ); % Gives two solutions
S1= S(1); % Extracting one solution
% Want to use solution as function handle.
func =@(y) S1;

回答(1 个)

Sai Bhargav Avula
I_sc value is an object of the sfit. The solve function requires a polynomial expression. Using the attributes(coeffvalues,coeffnames) of sfit object the function handle for the polynomial can be obtained.
% Extract coefficient names
names = coeffnames(I_sc);
I_sc_expression = 0;
% Looping to construct the polynomial expression.
for i = 1:numel(names)
name = names{i};
I_sc_expression = I_sc_expression + I_sc.(name)* (x^str2double(name(2)) * y^str2double(name(3)));
end
eqn = I_sc_expression == I_sc_max;
S = solve( eqn, x ); % Gives two solutions
S1= S(1); % Extracting one solution
func =@(y)subs(S1,y);

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by