How do I use integration with syms?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have problem when I try to integration function in my work by use syms and int.
a=5156.2/(26.26).^3;
b=23.70/26.26:
c=15.24/26.26;
mec2=(0.511e+6)/26.26;
mpc2=931.4;
w=0.001:0.025:600;
rr=mec2/mpc2 ;
Te=rr*w;
Tmax=4*Te;
sym w
y=(a*w)./((w.^2-b^2).^2+c^2.*w.^2); % *w;
fun=@(w)(a*w)./((w.^2-b^2).^2+c^2.*w.^2)*w;
q = integral(fun,0,5.0140);
2 comentarios
Walter Roberson
el 17 de En. de 2018
You have posted
b=23.70/26.26:
It is not valid to have a : at that point. You probably want a ; there.
Torsten
el 17 de En. de 2018
fun=@(w)(a*w)./((w.^2-b^2).^2+c^2.*w.^2).*w;
Best wishes
Torsten.
Respuestas (1)
Walter Roberson
el 17 de En. de 2018
The most immediate problem is that your line
fun=@(w)(a*w)./((w.^2-b^2).^2+c^2.*w.^2)*w;
needs to be
fun=@(w)(a*w)./((w.^2-b^2).^2+c^2.*w.^2).*w;
However, your code is confused about whether w is to be a sym or numeric. You assign a numeric vector to w, and then later do
sym w
which is equivalent to the call
sym('w');
which calls upon the symbolic engine to create a symbol named w inside the symbolic engine, and to return an object returning to that symbol that lives in the engine, and then to throw away that object because it is not assigned to anything and you have used ; at the end of the line so that it is not displayed either. Perhaps you wanted
syms w
which would be equivalent to
w = sym('w');
which would store the reference to the symbolic engine object in the variable w
The line after that you calculate y using w, but you do not use y after that so there is no reason to calculate it.
Then you create fun as an anonymous function that uses w as the dummy parameter name, so inside fun, w does not refer to the numeric array and does not refer to the symbolic engine symbol: inside fun, w refers to whatever is passed in as the first parameter of fun.
You then call upon numeric integration of the anonymous function, using integral(). integral() passes in numeric vectors, so it is at that point that the difference between * and .* becomes important in your definition of fun.
If you had wanted to do symbolic integration to attempt to find a closed-form formula for the integral, then you should have constructed a symbolic expression or symbolic function and used int():
syms w
fsym = (a*w)./((w.^2-b^2).^2+c^2.*w.^2).*w;
int(fsym, 0, 5.0140)
I would advise, though, that it makes no logical sense to request a closed form integral of a function defined in terms of floating point values such as 5156.2 . Such values are calculated as binary floating point, which cannot exactly represent multiples of 1/10 . For example the value 5156.2 would become 5156.1999999999998181010596454143524169921875 . In science, the notation 5156.2 indicates "some number in the semi-open range [5156 15/100, 5156 25/100) -- and since your coefficients are uncertain, it makes no sense to ask for an exact value from the integral. I would therefore suggest to you that working symbolically is not the right thing to do in this situation.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!