MATLAB: Trying to use quadv for a symbolic function

functionsquadvsymbolic functionssymbolic variable

Hello all,
I am planning on running the quadv routine on a function that has been symbolically created, and am having trouble.
What I did was to first create a function that within it, involves symbolic variables x1 and x2. (doesn't work)
I want to be able to run the quadv function on only one of the parameters given, say x1, so that the final integrated solution only varies in x2.
Here is a simple representation of what I have right now:
function fun=myfun(alpha)
syms x1 x2
fun=x1*x2%function itself simplified to visualize concept
subs(fun,'x2',alpha)
end
%another program
quadv(myfun,1,2000)% this will perform integration on x2 so when done function % will be in x.
Any help will be appreciated. Also, as a side question- is there any way to create a function and also call the function in the same file?
thanks to all in advance.

Best Answer

One thing you need to do is change your call
quadv(myfun,1,2000)
to
quadv(@myfun,1,2000)
To answer your side question:
Yes, if you create a function you can call it from the same routine. If you wrote the function in the form of a .m file, then if you are changing that .m file as you go, you need to "clear" the function before you can call it (or else you might get the old function.)
If you create a function handle in a routine, there is no problem calling upon the function in the routine. For example,
f = @(x) x.^2;
f(1:20)
To address your main question: it appears you are trying to use quadv() to come out with something that is intended to be a symbolic expression. You cannot do that: quadv() is strictly for numeric expressions.
Have you considered using int() ?
syms x2
int(myfun(x2), x2, 1, 2000)