Clear Filters
Clear Filters

Why is there a significant difference in the assignment results of functions using "subs" and "feval"

2 views (last 30 days)
I need a large amount of data for assignment, and I need to use the handle function to accelerate it, but the result calculated using "feval" is unacceptable
clear,clc
syms z
load FF.mat Th3
z3 = 0.0016:0.00022:0.006;
T1 = vpa(subs(Th3,z,z3));
disp(vpa(T1.',14))
Th3f = matlabFunction(Th3);
T2 = feval(Th3f,z3);
disp(T2.')
3.5028 3.9585 4.4094 4.8132 5.1376 5.3597 5.4692 5.4640 5.3344 5.0730 4.6994 3.9508 2.9207 0.9343 -2.8567 -7.1941 -31.3176 -55.4727 -173.9580 -324.4082 -787.7051
  3 Comments
sen
sen on 6 Dec 2023
According to the formula for solving, the last result needs to be close to 0, while the calculated result for “feval” is -787.7051
sen
sen on 6 Dec 2023
Thank you for your reply. Could you please run the code I submitted? I would like to know how to use "feval" to obtain results that are close to those obtained by "subs"

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 6 Dec 2023
Edited: Walter Roberson on 6 Dec 2023
syms z
load FF.mat Th3
z3 = 0.0016:0.00022:0.006;
T1 = vpa(subs(Th3,z,z3));
disp(vpa(T1.',14))
Th3f = matlabFunction(Th3);
T2 = feval(Th3f,z3);
format long g
disp(T2.')
3.50282686149745 3.95854248851538 4.40936088562012 4.8132483959198 5.13755702972412 5.35973119735718 5.46921586990356 5.46400547027588 5.33437728881836 5.07296371459961 4.69937896728516 3.95075988769531 2.92066955566406 0.934326171875 -2.856689453125 -7.194091796875 -31.317626953125 -55.47265625 -173.9580078125 -324.408203125 -787.705078125
T12 = double(T1(:)) - T2(:);
disp(T12)
7.52585900190006e-05 0.000255996608482079 0.000548036419161235 0.00103877265106078 0.00206573817902189 0.00575961188859786 0.0133017952813956 0.0256612421124434 0.0564997901084956 0.119048502399311 0.199439386434167 0.565610566987848 1.12954361764356 2.57470185401177 5.76486565117093 9.46704282663683 32.957595256356 56.5276612838938 174.523944755596 324.618623611357 787.705078125
plot(z3, T12)
  13 Comments

Sign in to comment.

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!