How do i further simplify this solution in matlab. I have used the simplify(.....) but it still gives me the same solution with the sin functions.
5 views (last 30 days)
Show older comments
George Adomako Kumi
on 1 Nov 2022
Commented: George Adomako Kumi
on 1 Nov 2022
syms z
syms L
syms z1
syms za
z1= 0.5*L;
pi = 3.1412;
L = 33.65;
valueBxx1=int(sin(pi*z1/L)^2 ,z, 0, L);
0 Comments
Accepted Answer
Gautam Chettiar
on 1 Nov 2022
The problem is arising in
z1 = 0.5 * L
, as first L is declared as a symbolic variable in
syms L
Later you assign a value to L, and hence it works on integration, however you still have its symbolic form in z1, and hence it returns an answer dependent on L
In short, you arent getting a simplified answer because your answer is an expression with a variable.
Try this:
syms z
syms z1
L = 33.65;
z1= 0.5*L;
pi = 3.1412;
valueBxx1=int(sin(pi*z1/L)^2 ,z, 0, L);
vpa(simplify(valueBxx1),3)
More Answers (1)
John D'Errico
on 1 Nov 2022
Edited: John D'Errico
on 1 Nov 2022
ARGH!!!!!! Why would you define the value of pi in MATLAB? Worse, then not even defining it to be the correct value?
pi already exists as a variable in MATLAB.
format long
pi
3.1412 is not even correctly rounded!
And worse yet, you are doing symbolic computations!!!!! Why spend the computing power to compute the wrong thing exactly?????
(Excuse me, as I go pound my head against a local brick wall. Ok. Now my head feels much better.)
syms z L z1 za
z1 = 0.5*L;
L = 33.65;
valueBxx1 = int(sin(pi*z1/L)^2 ,z, 0, L)
What would you want to see there? L is unknown, and it is inside the trig function. The sin of that expression is a FUNCTION OF L. Trig functions are NONLINEAR functions. As such, they have the fundamental property that they CANNOT be simplified. There is little more that could be done with it, since the value of L is unknown.
Could you force MATLAB to rewrite that expression using say a double angle formula for sin(x)^2? So I suppose we could use an identity like:
sin(u)^2 = (1 - (cos(2*u))/2
It will still have a cosine function of L. What more would you want to see?
simplify(valueBxx1,'steps',10,'all',true)
So the second of those choices does not have the square of a sine function in it. Is it materially different?
See Also
Categories
Find more on Assumptions 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!