如何使用fittype函数定义自定义方程式? [英] How can i use fittype function to define a custom equation?
问题描述
如何使用fittype函数定义以下自定义方程式?
How can I use fittype function to define the following custom equation?
y = a(x1^b)(x2^c)(x3^d)(x4^e)(x5^f)(x6^g).
我尝试了以下代码:
ft = fittype( 'a*(x1^b)*(x2^c)*(x3^d)*(x4^e)*(x5^f)*(x6^g)',...
'independent',{'x1','x2','x3','x4','x5','x6'},...
'dependent',{'y'},...
'coefficients',{'a','b','c','d','e','f','g'});
但是会引发此错误:
表达式a *(x1 ^ b)(x2 ^ c)(x3 ^ d)(x4 ^ e)(x5 ^ f)*(x6 ^ g )不是有效的MATLAB表达式,具有非标量系数,或者无法求值:FITTYPE函数的输入不足.
Expression a*(x1^b)(x2^c)(x3^d)(x4^e)(x5^f)*(x6^g) is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated: Not enough inputs to FITTYPE function.
推荐答案
首先,'a *(x1 ^ b)(x2 ^ c)(x3 ^ d)(x4 ^ e)(x5 ^ f)(x6 ^ g)'不是有效的MATLAB表达式.您应该将其更改为'a (x1.^ b).(x2.^ c).(x3.^ d).(x4.^ e).(x5.^f).*(x6.^g)'. 其次,Matlab无法处理这么多未知的参数,一个简短的参数就可以了,像这样:
Firstly, 'a*(x1^b)(x2^c)(x3^d)(x4^e)(x5^f)(x6^g)' is not a valid MATLAB expression. You should change it to 'a(x1.^b).(x2.^c).(x3.^d).(x4.^e).(x5.^f).*(x6.^g)'. Secondly, Matlab cannot process so many unknown parameters, a short one is OK, like this:
ft = fittype(@(a,b,c,x1,x2)a *(x1.^ b).*(x2.^ c), '独立',{'x1','x2'},'依赖',{'y'},'问题',{'b','c'}));
ft = fittype(@(a,b,c,x1,x2) a*(x1.^b).*(x2.^c), 'independent',{'x1','x2'},'dependent',{'y'},'problem',{'b','c'});
这篇关于如何使用fittype函数定义自定义方程式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!