Lsqcurvefit on function depending on syms
5 次查看(过去 30 天)
显示 更早的评论
Hi.
I'm using the int command to integrate a huge expression, using syms. The expression is saved in a variable "funk". In funk is a constant that I need to determine by fitting "funk" to my experimental data. For this I have tried to use lsqcurvefit, but I can't get this to work by simple putting "funk" in the expression where the function is suppose to be written. This is how it looks:
funk=huge expression with syms x
xdata=..
ydata=..
lsqcurvefit(@(x,xdata) funk, [some value] ,xdata,ydata)
How can I do this? Please help!
0 个评论
采纳的回答
Seth DeLand
2012-3-12
Hi Gustav,
You'll first need to use the matlabFunction command to convert the symbolic equation into a MATLAB function handle or file: http://www.mathworks.com/help/toolbox/symbolic/matlabfunction.html
There's an example here that should help: (see Figure 2) http://www.mathworks.com/tagteam/62669_91801v00_SymbolicGradient_Hessian_final.pdf
0 个评论
更多回答(2 个)
Gustav
2012-3-12
1 个评论
Seth DeLand
2012-3-13
Because funk is already a function handle (that's what matlabFunction created), you don't need to use the @(d,t) syntax when passing it to lsqcurvefit. You can just pass funk:
d = lsqcurvefit(funk,7,t,ydata)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!