Syms, fit and integral in a standalone app

Hi,
I have the following code that I want to compile in a standalone app :
syms z;
K_fit = fit(app.gdist,gK,'linearinterp');
func1= @(app,z)(K_fit(z).*(((z.^1-app.gdist(i,1)))));
gpot1(counter,1)=2*app.cz*integral(@(z)func1(app,z), app.gdist(i,1),max(app.gdist),'ArrayValued',true);
Can you tell how to rewrite it so that it doesn't use syms and is deployabe in a standalone app?
Thanks.

 Accepted Answer

That code never uses z in its sym form, so the syms z is not needed.
The definition of func1 uses z as an input parameter, so that "shadows" the previous definition of z as a symbol.
Meanwhile, your integral call is a numeric call, and you apply the numeric call to the anonymous function @(z)func1(app,z) which again "shadows" z .

2 Comments

Meanwhile, the replacement for the fit() is
[sortg, sortorder] = sort(app.gdist);
sortgK = gK(sortorder);
K_fit = @(z) interp1(sortg, sortgK, z, 'spline');
func1= @(app,z)(K_fit(z).*(((z.^1-app.gdist(i,1)))));
gpot1(counter,1)=2*app.cz*integral(@(z)func1(app,z), app.gdist(i,1),max(app.gdist),'ArrayValued',true);
Using 'spline' for the interp1 reduces the issue that the default 'linear' interpolation has a discontinuus derivative at every interpolation point. The documentation for integral() does not prohibit such functions, but if you are going to use linear interpolation then you really should add all of the interpolation points as 'Waypoints'
Simon
Simon on 25 Mar 2025
Moved: Steven Lord on 25 Mar 2025
It works. Thank you.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2024a

Asked:

on 24 Mar 2025

Moved:

on 25 Mar 2025

Community Treasure Hunt

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

Start Hunting!