trying to use quadv for a symbolic function?

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2012-12-19
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 个评论
Samuel
Samuel 2012-12-20
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 2012-12-20
Some functions can work with symbolic expressions, but quadv() is not one of them.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by