![untitled.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/201617/untitled.jpeg)
trying to find solutions to functions
4 次查看(过去 30 天)
显示 更早的评论
trying to find at least one solution for the following equations(individually - not on solution that fits both functions):
ya(x) = sin^3((2/(x+2))-3)
yb(x)=10x^2 exp(-2x)[sin(3x-pi)+cos(x^2)]
then id like to plot them and mark the solution with a blue diamond
i have the saved the functions individually
function [ya] = a3(x)
ya = (sin((2./(x+2))-3)).^3;
end
and
function [yb] = b3(x)
yb = 10.*x.^2.*exp(-2*x).*(sin(3*x-pi)+cos(x.^2))
end
and my code to find the solutions is:
sola3=fzero(@a3,0)
x=-5:0.1:5
yx=a3(x)
figure
plot(x,yx)
hold on
plot(sola3, a3(sola3), 'bd')
xlabel('X')
ylabel('Y')
title('solution to 3a')
solb3=fzero(@b3,0)
x=-5:0.1:5
yyx=b3(x)
figure
plot(x,yyx)
hold on
plot(solb3, b3(solb3), 'bd')
xlabel('X')
ylabel('Y')
title('solution to 3b')
but doesnt seem to be working
0 个评论
回答(1 个)
John D'Errico
2019-1-26
A solution to two equations ya and yb, in one unknown, x? It generally won't exist. Let me look at them.
ya = (sin((2./(x+2))-3)).^3;
I assume by solution, you mean a point where ya(x) == 0. You are using fzero, after all.
So, what do you know about a cube? z^3 is only zero, when zitself is zero. So we can freely look instead at the cube root. So ya is zero, whenever this expression is zero:
sin((2./(x+2))-3) == 0
When is sin(u) zero? u must be of the form u=n*pi, for integer n. Therefore, we have
2/(x+2) - 3 = n*pi
Solving for x, we find
x = 2/(3+n*pi) - 2
The principal solution lies at n=0, when we have x=-4/3, but there are infinitely many such solutions.
Now, consider yb.
yb = 10*x^2*exp(-2x)*[sin(3*x-pi)+cos(x^2)]
Clearly, x==0 is a solution, so we are done. You only needed one solution anyway. But a product of terms is zero when any member of the product is zero, and not otherwise. exp(-2*x) is never zero, and the last imte I checked 10 is generally never zero either, unless there is some new math I'm unaware of. That leaves the final term.
sin(3*x-pi)+cos(x^2)
I'm feeling too lazy to think for now, so lets throw it at solve and see what falls out.
syms x
solve(sin(3*x-pi)+cos(x^2))
ans =
3/2 - (9 - 2*pi)^(1/2)/2
(9 - 2*pi)^(1/2)/2 + 3/2
- (2*pi + 9)^(1/2)/2 - 3/2
(2*pi + 9)^(1/2)/2 - 3/2
Those appear not to be the only solutions though.
fplot(sin(3*x-pi)+cos(x^2))
refline([0,0])
![untitled.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/201617/untitled.jpeg)
But the one thing it appears you will probably not find is a solution the two functions have in common.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!