Can someone check whether my script is correct or not? I did this using the same method as the one last time.
2 次查看(过去 30 天)
显示 更早的评论
The last work from which I took reference: https://www.mathworks.com/matlabcentral/answers/2049237-what-is-the-function-to-use-to-find-the-intersection-of-two-graphs?s_tid=prof_contriblnk
My new work:
%%Plotting the graphs
k = @(x,y) y-3.*sin((x)^2);
fimplicit(k), grid on
hold on
m = @(x,y) y- exp(x/2) + exp(-2.*x);
fimplicit(m), grid on
hold off
xlabel('x'), ylabel('y')
legend ('y = 3 + sin(x^2)','y = e^(x/2) + e^(-2*x)','location','northeast')
When I ran the script, it showed this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1545367/image.png)
0 个评论
采纳的回答
Dyuman Joshi
2023-11-21
编辑:Dyuman Joshi
2023-11-21
There was a missing element-wise operator in the sin() in the definition of 'k'.
Also, I have modified the legend to show the expressions correctly.
% vv
k = @(x,y) y - 3.*sin((x).^2);
fimplicit(k), grid on
hold on
m = @(x,y) y - exp(x/2) + exp(-2.*x);
fimplicit(m), grid on
hold off
xlabel('x'); ylabel('y');
% v v v v
legend ('y = 3*sin(x^2)','y = e\^(x/2) - e\^(-2*x)','location','northeast')
3 个评论
Walter Roberson
2023-11-21
clear;
%% Plotting the graphs
k = @(x,y) y - 3.*sin((x).^2);
fimplicit(k), grid on
hold on
m = @(x,y) y - exp(x./2) - exp((-2).*x);
fimplicit(m), grid on
hold off
xlabel('x'); ylabel('y');
legend ('y = 3*sin(x^2)','y = e\^(x/2) + e\^(-2*x)','location','northeast')
%% Finding intersection points
fun1 = @(x) exp(x./2) + exp((-2).*x) - 3 .* sin((x).^2); % f(x) = g(x)
x0 = [0 2] % initial guesses
for j = 1:length(x0)
x(j) = fsolve(fun1, x0(j));
end
x
uniquetol(x)
%% Calculating the volume
fun2 = @(x) (3.*sin(x.^2)).^2 - (exp(x./2) - exp(-2.*x)).^2;
V = pi*integral (fun2,x(1),x(2))
更多回答(1 个)
Walter Roberson
2023-11-21
Are you sure you want
and not
? You currently square x before taking sin() -- which is certainly a valid operation, but is much less common than taking the sin of x and squaring the result.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1545382/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1545387/image.png)
%%Plotting the graphs
k = @(x,y) y-3.*sin((x).^2);
fimplicit(k), grid on
hold on
m = @(x,y) y- exp(x/2) + exp(-2.*x);
fimplicit(m), grid on
hold off
xlabel('x'), ylabel('y')
legend ('y = 3 + sin(x^2)','y = e^(x/2) + e^(-2*x)','location','northeast')
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!