Can someone check whether my script is correct or not? I did this using the same method as the one last time.
1 view (last 30 days)
Show older comments
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:
0 Comments
Accepted Answer
Dyuman Joshi
on 21 Nov 2023
Edited: Dyuman Joshi
on 21 Nov 2023
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 Comments
Walter Roberson
on 21 Nov 2023
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))
More Answers (1)
Walter Roberson
on 21 Nov 2023
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.
%%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')
See Also
Categories
Find more on 2-D and 3-D Plots 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!