trying to use quadv for a symbolic function?

1 view (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 19 Dec 2012
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)
  2 Comments
Samuel
Samuel on 20 Dec 2012
Thanks very much for the advice and help. In addition you were correct- I was trying to work with a symbolic expression inside a function call- I am not really used to using functions and was confused.
Walter Roberson
Walter Roberson on 20 Dec 2012
Some functions can work with symbolic expressions, but quadv() is not one of them.

Sign in to comment.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!