MATLAB: convert from euler (complex fourier) to sinus function (bn coefficients) - matlab

I have the following script
clc; clear all; close all;
syms x n
f = x;
L = 1;
subplot(2,1,1)
h = ezplot(f,[-L,L])
set(h, 'Color','r','LineWidth',1)
a0 = (1/L) * int(f * cos(0* pi*x/L),-L,L)
an = (1/L) * int(f * cos(n* pi*x/L),-L,L)
bn = (1/L)* int(f* sin(n* pi*x/L),-L,L)
fx = a0/2 + symsum((an* cos(n*pi*x/L) + bn* sin(n*pi*x/L)),n,1,5)
% for n =5, the answer: fx = (2*sin(pi*x))/pi - sin(2*pi*x)/pi +
%(2*sin(3*pi*x))/(3*pi) - sin(4*pi*x)/(2*pi) + (2*sin(5*pi*x))/(5*pi)
hold on
h = ezplot(fx,[-L,L])
grid on
%Solution with complex Fourier
c0 = (1/(2*L))*int(f*exp(-j*0*pi*x/L),-L,L)
cn = (1/(2*L))*int(f*exp(-j*n*pi*x/L),-L,L)
subplot(2,1,2)
h = ezplot(f,[-L,L])
set(h, 'Color','r','LineWidth',1)
fx_c = c0 + symsum(cn*exp(j*n*pi*x/L),n,-5,-1) + ...
symsum(cn*exp(j*n*pi*x/L),n,1,5) % n for complex -5,5
hold on
h = ezplot(fx_c,[-L,L])
grid on
My question: Since the answer of fx should be equal to fx_c (complex fourier). We can see from the figures produced by these 2 functions. They are same. But
fx =
(2*sin(pi*x))/pi - sin(2*pi*x)/pi + (2*sin(3*pi*x))/(3*pi) - sin(4*pi*x)/(2*pi) + (2*sin(5*pi*x))/(5*pi)
and
fx_c =
exp(-pi*x*i)*((pi*i - 1)/(2*pi^2) + (pi*i + 1)/(2*pi^2)) - exp(pi*x*i)*((pi*i - 1)/(2*pi^2) + (pi*i + 1)/(2*pi^2)) - exp(-pi*x*2*i)*((pi*2*i - 1)/(8*pi^2) + (pi*2*i + 1)/(8*pi^2)) + exp(pi*x*2*i)*((pi*2*i - 1)/(8*pi^2) + (pi*2*i + 1)/(8*pi^2)) + exp(-pi*x*3*i)*((pi*3*i - 1)/(18*pi^2) + (pi*3*i + 1)/(18*pi^2)) - exp(pi*x*3*i)*((pi*3*i - 1)/(18*pi^2) + (pi*3*i + 1)/(18*pi^2)) - exp(-pi*x*4*i)*((pi*4*i - 1)/(32*pi^2) + (pi*4*i + 1)/(32*pi^2)) + exp(pi*x*4*i)*((pi*4*i - 1)/(32*pi^2) + (pi*4*i + 1)/(32*pi^2)) + exp(-pi*x*5*i)*((pi*5*i - 1)/(50*pi^2) + (pi*5*i + 1)/(50*pi^2)) - exp(pi*x*5*i)*((pi*5*i - 1)/(50*pi^2) + (pi*5*i + 1)/(50*pi^2))
How to convert fx_c to be fx?

They are related by Euler's formula. You can check it with rewrite command:
>> rewrite(exp(1i*x), 'cos')
ans =
cos(x) + sin(x)*1i
Applying it to your function and simplifying a bit, you can get to the same expression:
>> expand(rewrite(fx_c, 'cos'), 'ArithmeticOnly', true)
ans =
(2*sin(pi*x))/pi - sin(2*pi*x)/pi + (2*sin(3*pi*x))/(3*pi) - sin(4*pi*x)/(2*pi) + (2*sin(5*pi*x))/(5*pi)
>> fx
fx =
(2*sin(pi*x))/pi - sin(2*pi*x)/pi + (2*sin(3*pi*x))/(3*pi) - sin(4*pi*x)/(2*pi) + (2*sin(5*pi*x))/(5*pi)

Related

Matlab Numeric Solvers outputting: Warning: Unable to find explicit solution

I have 9 equations and 9 unknowns that I need to solve for, but when I set up the code and run it I get the following:
"Warning: Unable to find explicit solution. For options, see help.
In sym/solve (line 317)
In HW2_PartA (line 65)
ans =
Empty sym: 0-by-1"
I have tried using both the solve functions and the vpasolve functions and I receive the same message each time.
The code is:
clear all
clc
syms T0 nO2 nH2 nH nOH nH2O nO lO lH
t = T0/1000;
R = 8.314;
nF = 1;
nOX = 11/32;
P0 = 5.3e6; % Pa
Pstp = 101.3e3;%Pa
hfH2 = 0; %j/mol
hfO2 = 0; %j/mol
hfH2O = -241.82e3;% j/mol
hfO = 249.19e3; %j/mol
hfH = 218e3;%J/mol
hfOH = 39.46e3;%j/mol
oxygengas = [20.9111 10.721071 -2.020498 0.046449 9.245722 5.337651 237.6185 0.00];
hydrogengas = [43.4136 -4.2931 1.2724 -0.0969 -20.5339 -38.5152 162.0814 0.00];
hydrogen = [20.7860 0.0000 -0.0000 0.0000 0.0000 211.8020 139.8711 217.9990];
OHgas = [28.7470 4.7145 -0.8147 0.0547 -2.7478 26.4144 214.1166 38.9871];
water = [41.9643 8.6221 -1.4998 0.0981 -11.1576 -272.1797 219.7809 -241.8264];
%Enthalpy
hO2 = 1000*(oxygengas*t + oxygengas(2)*(t^2)/2 + oxygengas(3)*(t^3)/3 + oxygengas(4)*(t^4)/4 -
oxygengas(5)/t + oxygengas(6) - oxygengas(8));
hH2 = 1000*(hydrogengas(1)*t + hydrogengas(2)*(t^2)/2 + hydrogengas(3)*(t^3)/3 + hydrogengas(4)*
(t^4)/4 - hydrogengas(5)/t + hydrogengas(6) - hydrogengas(8));
hH = 1000*(hydrogen(1)*t + hydrogen(2)*(t^2)/2 + hydrogen(3)*(t^3)/3 + hydrogen(4)*(t^4)/4 -
hydrogen(5)/t + hydrogen(6) - hydrogen(8));
hOH = 1000*(OHgas(1)*t + OHgas(2)*(t^2)/2 + OHgas(3)*(t^3)/3 + OHgas(4)*(t^4)/4 - OHgas(5)/t +
OHgas(6) - OHgas(8));
hO = hH;
hH2O = 1000*(water(1)*t + water(2)*(t^2)/2 + water(3)*(t^3)/3 + water(4)*(t^4)/4 - water(5)/t +
water(6) - water(8));
%Entropy
sO2 = oxygengas(1)*log(t) + oxygengas(2)*t + oxygengas(3)*(t^2)/2 +oxygengas(4)*(t^3)/3 -
oxygengas(5)/(2*t^2) +oxygengas(7);
sH2 = hydrogengas(1)*log(t) + hydrogengas(2)*t + hydrogengas(3)*(t^2)/2 +hydrogengas(4)*(t^3)/3 -
hydrogengas(5)/(2*t^2) +hydrogengas(7);
sH = hydrogen(1)*log(t) + hydrogen(2)*t + hydrogen(3)*(t^2)/2 +hydrogen(4)*(t^3)/3 -
hydrogen(5)/(2*t^2) +hydrogen(7);
sOH = OHgas(1)*log(t) + OHgas(2)*t + OHgas(3)*(t^2)/2 +OHgas(4)*(t^3)/3 - OHgas(5)/(2*t^2) +OHgas(7);
sO = (5/2)*R*log(T0/298.15) + 161.003;
sH2O = water(1)*log(t) + water(2)*t + water(3)*(t^2)/2 +water(4)*(t^3)/3 - water(5)/(2*t^2)
+water(7);
%Mass continuity
eqn1 = 2*nO2 + nOH + nO +nH2O - 2*nOX == 0;
eqn2 = 2*nH2 + 2*nH2O + nOH + nH - 2*nF == 0;
%Minimizing Gibbs Free Energy
%Oxygen Gas
eqn3 = hO2 + hfO2 - T0*sO2 + R*T0*log(P0/Pstp) + R*T0*log(nO2/(nO2+nH2+nH+nOH+nO+nH2O)) + 2*lO ==0 ;
%Hydrogen Gas
eqn4 = hH2 + hfH2 - T0*sH2 + R*T0*log(P0/Pstp) + R*T0*log(nH2/(nO2+nH2+nH+nOH+nO+nH2O)) + 2*lH == 0;
%Hydrogen
eqn5 = hH + hfH - T0*sH + R*T0*log(P0/Pstp) + R*T0*log(nH/(nO2+nH2+nH+nOH+nO+nH2O)) + lH == 0;
%OH Gas
eqn6 = hOH + hfOH - T0*sOH + R*T0*log(P0/Pstp) + R*T0*log(nOH/(nO2+nH2+nH+nOH+nO+nH2O)) + lO + lH ==
0;
%Oxygen
eqn7 = hO + hfO - T0*sO + R*T0*log(P0/Pstp) + R*T0*log(nO/(nO2+nH2+nH+nOH+nO+nH2O)) + lO == 0;
%Water
eqn8 = hH2O + hfH2O - T0*sO2 + R*T0*log(P0/Pstp) + R*T0*log(nH2O/(nO2+nH2+nH+nOH+nO+nH2O)) + 2*lH +
lO == 0;
% Enthalpy Balance
eqn9 = nO2*hO2 + nH2*hH2 + nH*hH + nOH*hOH + nO*hO + nH2O*hH2O - nOX*hfO2 - nF*hfH2 + nO2*hfO2 +
nH2*hfH2 + nH*hfH + nOH*hfOH + nO*hfOH + nH2O*hfH2O == 0;
eqns = [eqn1,eqn2,eqn3,eqn4,eqn5, eqn6, eqn7, eqn8, eqn9];
sol = solve([eqn1,eqn2,eqn3,eqn4,eqn5,eqn6,eqn7,eqn8,eqn9], [T0 nO2 nH2 nH nOH nH2O nO lO lH]);
sol.T0

How to fix Matlab Solve Calculation Error/solver gives a variable back instead of a numerical answer?

I'm trying to solve for q. However, this error, in the image attached, shows up and I have no clue how to fix it. The code runs smoothly without the fifth blob [k5*z5/(1+q*(k5-1))] in the equation and it solves for q. But when I add it to the equation, you get the error... Help....
z1 = 0.01188354;
z2 = 0.20291147;
z3 = 0.03386809;
z4 = 0.6087344;
z5 = 0.1426025;
k1 = 0.00211577;
k2 = 433.816504;
k3 = 0.00651267;
k4 = 12.8652437;
k5 = 3.25E-06;
syms q
eqn = k1*z1/(1+q*(k1-1)) + k2*z2/(1+q*(k2-1)) + k3*z3/(1+q*(k3-1)) + k4*z4/(1+q*(k4-1))+ k5*z5/(1+q*(k5-1)) == 1;
qvalue = solve(eqn,q,'Real',true)
You messed a bit with solve. It looks like your equation doesn't have real solution and you force it with 'Real',true It should be:
z1 = 0.01188354;
z2 = 0.20291147;
z3 = 0.03386809;
z4 = 0.6087344;
z5 = 0.1426025;
k1 = 0.00211577;
k2 = 433.816504;
k3 = 0.00651267;
k4 = 12.8652437;
k5 = 3.25E-06;
syms q
eqn = k1*z1/(1+q*(k1-1)) + k2*z2/(1+q*(k2-1)) + k3*z3/(1+q*(k3-1)) + k4*z4/(1+q*(k4-1))+ k5*z5/(1+q*(k5-1)) == 1;
qvalue = solve(eqn,q)
And the output is:
root(z^5 - (553951988707451897271725042874967932463648393519489496501295701298760653356885564069*z^4)/146344515065711958525050250689493211538989295698771861545387136571113311336350613504 + (877647369043978904163970290106419962713606423192038983322127636310825879207936*z^3)/164487327751721471763565140886077743965784030575734255347857322244873703346919 - (3796080934806054258394941458065140559250786119491250988496078448019381612969984*z^2)/1151411294262050302344955986202544207760488214030139787435001255714115923428433 + (838076006172751803233223399262272123114675605549658858976242221943722830987264*z)/1151411294262050302344955986202544207760488214030139787435001255714115923428433 + 21452770321210561747759866301918995558818778263453224281332504760441104236544/1151411294262050302344955986202544207760488214030139787435001255714115923428433, z, 1)
root(z^5 - (553951988707451897271725042874967932463648393519489496501295701298760653356885564069*z^4)/146344515065711958525050250689493211538989295698771861545387136571113311336350613504 + (877647369043978904163970290106419962713606423192038983322127636310825879207936*z^3)/164487327751721471763565140886077743965784030575734255347857322244873703346919 - (3796080934806054258394941458065140559250786119491250988496078448019381612969984*z^2)/1151411294262050302344955986202544207760488214030139787435001255714115923428433 + (838076006172751803233223399262272123114675605549658858976242221943722830987264*z)/1151411294262050302344955986202544207760488214030139787435001255714115923428433 + 21452770321210561747759866301918995558818778263453224281332504760441104236544/1151411294262050302344955986202544207760488214030139787435001255714115923428433, z, 2)
root(z^5 - (553951988707451897271725042874967932463648393519489496501295701298760653356885564069*z^4)/146344515065711958525050250689493211538989295698771861545387136571113311336350613504 + (877647369043978904163970290106419962713606423192038983322127636310825879207936*z^3)/164487327751721471763565140886077743965784030575734255347857322244873703346919 - (3796080934806054258394941458065140559250786119491250988496078448019381612969984*z^2)/1151411294262050302344955986202544207760488214030139787435001255714115923428433 + (838076006172751803233223399262272123114675605549658858976242221943722830987264*z)/1151411294262050302344955986202544207760488214030139787435001255714115923428433 + 21452770321210561747759866301918995558818778263453224281332504760441104236544/1151411294262050302344955986202544207760488214030139787435001255714115923428433, z, 3)
root(z^5 - (553951988707451897271725042874967932463648393519489496501295701298760653356885564069*z^4)/146344515065711958525050250689493211538989295698771861545387136571113311336350613504 + (877647369043978904163970290106419962713606423192038983322127636310825879207936*z^3)/164487327751721471763565140886077743965784030575734255347857322244873703346919 - (3796080934806054258394941458065140559250786119491250988496078448019381612969984*z^2)/1151411294262050302344955986202544207760488214030139787435001255714115923428433 + (838076006172751803233223399262272123114675605549658858976242221943722830987264*z)/1151411294262050302344955986202544207760488214030139787435001255714115923428433 + 21452770321210561747759866301918995558818778263453224281332504760441104236544/1151411294262050302344955986202544207760488214030139787435001255714115923428433, z, 4)
root(z^5 - (553951988707451897271725042874967932463648393519489496501295701298760653356885564069*z^4)

How to separate the real and imaginary parts of a transfer function?

Here is a transfer function:
S = [tf([10 2 4],[1 95 2000 3450])];
How can I get real(S) and Imag(S)?
It sounds like you want the Fourier form of your transfer function. As far as I know, there's no builtin function for this so you'll need to use symbolic math:
num = [10 2 4];
den = [1 95 2000 3450];
syms s;
syms omega real; % Define as real-valued
f1 = poly2sym(num,s)/poly2sym(den,s)
f2 = subs(f1,s,1i*omega)
f2_real = simplify(real(f2))
f2_imag = simplify(imag(f2))
which returns
f1 =
(10*s^2 + 2*s + 4)/(s^3 + 95*s^2 + 2000*s + 3450)
f2 =
(- 10*omega^2 + omega*2i + 4)/(- omega^3*1i - 95*omega^2 + omega*2000i + 3450)
f2_real =
(4*(237*omega^4 - 7720*omega^2 + 3450))/(omega^6 + 5025*omega^4 + 3344500*omega^2 + 11902500)
f2_imag =
-(2*omega*(5*omega^4 - 9907*omega^2 + 550))/(omega^6 + 5025*omega^4 + 3344500*omega^2 + 11902500)
You can then use subs and vpa/double to evaluate these for a particular value of omega.

MATLAB's 'solve,' applied to a system of equations, gives me a solution that doesn't satisfy one of the equations

I'm using the MATLAB function 'solve' to solve a system of six equations and six variables. In the solution it gives, at least one of the equations seems not to be satisfied. Here's my code for the problem:
% given parameters
alpha = .05; % exogenous rate of cost reductions
sigma = .05; % exogenous uncertainty (infinitessimal st dev)
p0 = 10; % initial carbon price
p1 = 50; % carbon price under policy
lambda_p = .05; % Poisson arrival rate of policy
lambda_q = .01; % Probability of reversion to no policy state
r = .03; % discount rate
% exponents for solution
beta1 = (.5*sigma^2 + alpha + sqrt((.5*sigma^2 + alpha)^2 + 2*sigma^2*(r+lambda_p)))/sigma^2;
beta2 = (.5*sigma^2 + alpha - sqrt((.5*sigma^2 + alpha)^2 + 2*sigma^2*(r+lambda_p)))/sigma^2;
beta3 = (.5*sigma^2 + alpha - sqrt((.5*sigma^2 + alpha)^2 + 2*sigma^2*r))/sigma^2;
beta4 = (.5*sigma^2 + alpha - sqrt((.5*sigma^2 + alpha)^2 + 2*sigma^2*(r+lambda_p+lambda_q)))/sigma^2;
syms a0 a1 ka ks B1 B2
S = solve(p1 - a1 == (lambda_p*lambda_q*ka*a1^beta3 + lambda_q*ks*a1^beta4)/(lambda_p + lambda_q), ...
-1 == (lambda_p*lambda_q*ka*beta3*a1^(beta3-1) + lambda_q*ks*beta4*a1^(beta4-1))/(lambda_p + lambda_q), ...
p0 - a0 == B1*a0^beta1 + B2*a0^beta2 - lambda_p*a0/(alpha+lambda_p+r) + lambda_p*p1/(r+lambda_p), ...
-1 == B1*beta1*a0^(beta1-1) + B2*beta2*a0^(beta2-1) - lambda_p/(alpha+lambda_p+r), ...
(lambda_p*lambda_q*ka*a1^beta3 - lambda_p*ks*a1^beta4)/(lambda_p + lambda_q) == B1*a1^beta1 + B2*a1^beta2 - lambda_p*a1/(alpha+lambda_p+r) + lambda_p*p1/(r+lambda_p), ...
(lambda_p*lambda_q*ka*beta3*a1^(beta3-1) - lambda_p*ks*beta4*a1^(beta4-1))/(lambda_p + lambda_q) == B1*beta1*a1^(beta1-1) + B2*beta2*a1^(beta2-1) - lambda_p/(alpha+lambda_p+r));
The third equation isn't satisfied. When I obtain the output S, I calculate
>> p0-S.a0
ans =
-51.139888401602841212761952348352
and
>> S.B1*S.a0^beta1 + S.B2*S.a0^beta2 - lambda_p*S.a0/(alpha+lambda_p+r) + lambda_p*p1/(r+lambda_p)
ans =
4.58887467530944339251344448794
which aren't equal. Any ideas as to what's wrong? Thanks.

using quad to integrate function with respect to just one variable

is there any way i can integrate function of two variable, say
f=#(x) x^2 + x*y
over just x
tried quad(f, a, b)
but doesn't work, looking for alternative solution
Looks like you want something like this:
y = 100; % whatever y is
a = 0;
b = 2;
% you'll need to vectorize the integrand function
f = #(x) x.*x + x.*y
val = quad(f, a, b);
However, if you are looking for an algebraic answer, you'll need to use the Symbolic Toolbox, or some other software, or your calculus book. :-)
The whole "vectorize" thing comes from the Mathworks quad documentation that says:
The function y = fun(x) should accept a vector argument x and return a vector result y, the integrand evaluated at each element of x.
Sorry, but quad does not solve symbolic problems. It does only numerical integration.
syms x y
int(x^2 + x*y,x)
ans =
(x^2*(2*x + 3*y))/6
The natural way to solve a symbolic problem is to use a symbolic tool.
From the followup, Anya wants something in-between. To steal the words of an old rock star named Mick, "You can't always get what you want."
Again, quad can't be used if you wish to integrate ONLY over x, as quad is an adaptive tool.
In SOME SIMPLE cases, you can use a simple tool like Simpson's rule to do the work. For example, suppose you wanted to solve the above problem, with x integrated over the interval [0 1]. For purposes of comparison, I'll do it symbolically first.
syms x y
res = int(x^2 + x*y,x);
subs(res,x,1) - subs(res,0)
ans =
y/2 + 1/3
Now, lets try it using a numerical integration on x.
syms y
x = 0:.01:1;
coef = mod((0:100)',2)*2 + 2;
coef([1 end]) = 1;
coef = 0.01*coef/3;
(x.^2 + x.*y)*coef
ans =
y/2 + 1/3
So in this very SIMPLE case, it did work. How about something a little more complicated? Integrate x*exp(x*y) over the interval [-1 1]. Again, a known form is accessible symbolically.
syms x y
res = int(x*exp(x*y),x);
res = subs(res,x,1) - subs(res,-1)
res =
(exp(-y)*(y + 1))/y^2 + (exp(y)*(y - 1))/y^2
To test it out later, what value does this take on at y = 1/2?
vpa(subs(res,y,1/2))
ans =
0.34174141687554424792549563431876
Lets try the same trick, using Simpson's rule.
syms y
x = -1:.01:1;
coef = mod((-100:100)',2)*2 + 2;
coef([1 end]) = 1;
coef = 0.01*coef/3;
res = (x.*exp(x*y))*coef
res =
exp(y/2)/300 - exp(-y/2)/300 - exp(-y)/300 - exp(-y/4)/300 + exp(y/4)/300 - exp(-y/5)/750 + exp(y/5)/750 - exp(-(3*y)/4)/100 - exp(-(2*y)/5)/375 + exp((2*y)/5)/375 + exp((3*y)/4)/100 - exp(-(3*y)/5)/250 + exp((3*y)/5)/250 - (2*exp(-(4*y)/5))/375 + (2*exp((4*y)/5))/375 - exp(-y/10)/1500 + exp(y/10)/1500 - exp(-(3*y)/10)/500 + exp((3*y)/10)/500 - (7*exp(-(7*y)/10))/1500 + (7*exp((7*y)/10))/1500 - (3*exp(-(9*y)/10))/500 + (3*exp((9*y)/10))/500 - exp(-y/20)/1500 + exp(y/20)/1500 - exp(-(3*y)/20)/500 + exp((3*y)/20)/500 - exp(-y/25)/3750 + exp(y/25)/3750 - (7*exp(-(7*y)/20))/1500 - exp(-(2*y)/25)/1875 + exp((2*y)/25)/1875 + (7*exp((7*y)/20))/1500 - exp(-(3*y)/25)/1250 + exp((3*y)/25)/1250 - (3*exp(-(9*y)/20))/500 - (2*exp(-(4*y)/25))/1875 + (2*exp((4*y)/25))/1875 + (3*exp((9*y)/20))/500 - (11*exp(-(11*y)/20))/1500 - exp(-(6*y)/25)/625 + exp((6*y)/25)/625 + (11*exp((11*y)/20))/1500 - (7*exp(-(7*y)/25))/3750 + (7*exp((7*y)/25))/3750 - (13*exp(-(13*y)/20))/1500 - (4*exp(-(8*y)/25))/1875 + (4*exp((8*y)/25))/1875 + (13*exp((13*y)/20))/1500 - (3*exp(-(9*y)/25))/1250 + (3*exp((9*y)/25))/1250 - (11*exp(-(11*y)/25))/3750 + (11*exp((11*y)/25))/3750 - (17*exp(-(17*y)/20))/1500 - (2*exp(-(12*y)/25))/625 + (2*exp((12*y)/25))/625 + (17*exp((17*y)/20))/1500 - (13*exp(-(13*y)/25))/3750 + (13*exp((13*y)/25))/3750 - (19*exp(-(19*y)/20))/1500 - (7*exp(-(14*y)/25))/1875 + (7*exp((14*y)/25))/1875 + (19*exp((19*y)/20))/1500 - (8*exp(-(16*y)/25))/1875 + (8*exp((16*y)/25))/1875 - (17*exp(-(17*y)/25))/3750 + (17*exp((17*y)/25))/3750 - (3*exp(-(18*y)/25))/625 + (3*exp((18*y)/25))/625 - (19*exp(-(19*y)/25))/3750 + (19*exp((19*y)/25))/3750 - (7*exp(-(21*y)/25))/1250 + (7*exp((21*y)/25))/1250 - (11*exp(-(22*y)/25))/1875 + (11*exp((22*y)/25))/1875 - (23*exp(-(23*y)/25))/3750 + (23*exp((23*y)/25))/3750 - (4*exp(-(24*y)/25))/625 + (4*exp((24*y)/25))/625 - exp(-y/50)/7500 + exp(y/50)/7500 - exp(-(3*y)/50)/2500 + exp((3*y)/50)/2500 - (7*exp(-(7*y)/50))/7500 + (7*exp((7*y)/50))/7500 - (3*exp(-(9*y)/50))/2500 + (3*exp((9*y)/50))/2500 - (11*exp(-(11*y)/50))/7500 + (11*exp((11*y)/50))/7500 - (13*exp(-(13*y)/50))/7500 + (13*exp((13*y)/50))/7500 - (17*exp(-(17*y)/50))/7500 + (17*exp((17*y)/50))/7500 - (19*exp(-(19*y)/50))/7500 + (19*exp((19*y)/50))/7500 - (7*exp(-(21*y)/50))/2500 + (7*exp((21*y)/50))/2500 - (23*exp(-(23*y)/50))/7500 + (23*exp((23*y)/50))/7500 - (9*exp(-(27*y)/50))/2500 + (9*exp((27*y)/50))/2500 - (29*exp(-(29*y)/50))/7500 + (29*exp((29*y)/50))/7500 - (31*exp(-(31*y)/50))/7500 + (31*exp((31*y)/50))/7500 - (11*exp(-(33*y)/50))/2500 + (11*exp((33*y)/50))/2500 - (37*exp(-(37*y)/50))/7500 + (37*exp((37*y)/50))/7500 - (13*exp(-(39*y)/50))/2500 + (13*exp((39*y)/50))/2500 - (41*exp(-(41*y)/50))/7500 + (41*exp((41*y)/50))/7500 - (43*exp(-(43*y)/50))/7500 + (43*exp((43*y)/50))/7500 - (47*exp(-(47*y)/50))/7500 + (47*exp((47*y)/50))/7500 - (49*exp(-(49*y)/50))/7500 + (49*exp((49*y)/50))/7500 - exp(-y/100)/7500 + exp(y/100)/7500 - exp(-(3*y)/100)/2500 + exp((3*y)/100)/2500 - (7*exp(-(7*y)/100))/7500 + (7*exp((7*y)/100))/7500 - (3*exp(-(9*y)/100))/2500 + (3*exp((9*y)/100))/2500 - (11*exp(-(11*y)/100))/7500 + (11*exp((11*y)/100))/7500 - (13*exp(-(13*y)/100))/7500 + (13*exp((13*y)/100))/7500 - (17*exp(-(17*y)/100))/7500 + (17*exp((17*y)/100))/7500 - (19*exp(-(19*y)/100))/7500 + (19*exp((19*y)/100))/7500 - (7*exp(-(21*y)/100))/2500 + (7*exp((21*y)/100))/2500 - (23*exp(-(23*y)/100))/7500 + (23*exp((23*y)/100))/7500 - (9*exp(-(27*y)/100))/2500 + (9*exp((27*y)/100))/2500 - (29*exp(-(29*y)/100))/7500 + (29*exp((29*y)/100))/7500 - (31*exp(-(31*y)/100))/7500 + (31*exp((31*y)/100))/7500 - (11*exp(-(33*y)/100))/2500 + (11*exp((33*y)/100))/2500 - (37*exp(-(37*y)/100))/7500 + (37*exp((37*y)/100))/7500 - (13*exp(-(39*y)/100))/2500 + (13*exp((39*y)/100))/2500 - (41*exp(-(41*y)/100))/7500 + (41*exp((41*y)/100))/7500 - (43*exp(-(43*y)/100))/7500 + (43*exp((43*y)/100))/7500 - (47*exp(-(47*y)/100))/7500 + (47*exp((47*y)/100))/7500 - (49*exp(-(49*y)/100))/7500 + (49*exp((49*y)/100))/7500 - (17*exp(-(51*y)/100))/2500 + (17*exp((51*y)/100))/2500 - (53*exp(-(53*y)/100))/7500 + (53*exp((53*y)/100))/7500 - (19*exp(-(57*y)/100))/2500 + (19*exp((57*y)/100))/2500 - (59*exp(-(59*y)/100))/7500 + (59*exp((59*y)/100))/7500 - (61*exp(-(61*y)/100))/7500 + (61*exp((61*y)/100))/7500 - (21*exp(-(63*y)/100))/2500 + (21*exp((63*y)/100))/2500 - (67*exp(-(67*y)/100))/7500 + (67*exp((67*y)/100))/7500 - (23*exp(-(69*y)/100))/2500 + (23*exp((69*y)/100))/2500 - (71*exp(-(71*y)/100))/7500 + (71*exp((71*y)/100))/7500 - (73*exp(-(73*y)/100))/7500 + (73*exp((73*y)/100))/7500 - (77*exp(-(77*y)/100))/7500 + (77*exp((77*y)/100))/7500 - (79*exp(-(79*y)/100))/7500 + (79*exp((79*y)/100))/7500 - (27*exp(-(81*y)/100))/2500 + (27*exp((81*y)/100))/2500 - (83*exp(-(83*y)/100))/7500 + (83*exp((83*y)/100))/7500 - (29*exp(-(87*y)/100))/2500 + (29*exp((87*y)/100))/2500 - (89*exp(-(89*y)/100))/7500 + (89*exp((89*y)/100))/7500 - (91*exp(-(91*y)/100))/7500 + (91*exp((91*y)/100))/7500 - (31*exp(-(93*y)/100))/2500 + (31*exp((93*y)/100))/2500 - (97*exp(-(97*y)/100))/7500 + (97*exp((97*y)/100))/7500 - (33*exp(-(99*y)/100))/2500 + (33*exp((99*y)/100))/2500 + exp(y)/300
So I got a result, but its not the analytical one I wanted, and a bit of a nasty mess. Is it correct?
vpa(subs(res,y,1/2))
ans =
0.34174141693463006644516447861307
I'll copy the analytical result from above so we can compare...
0.34174141687554424792549563431876
As you can see, Simpson's rule, at a step size of 0.01 over [-1,1], did reasonably well, agreeing out to about 9 decimal digits.
There is no assurance that this technique will work as well on any more general kernel, but it might give you what you desire.