surf plot is required
4 次查看(过去 30 天)
显示 更早的评论
A = 1; M = 1; Da = 0.1; L = 0.1; Pr = 1; Nb = 0.1; Nt = 0.5; s = 0.5; Le = 2; Kc = 1;B = 0.5;Lv = linspace(-2,2,100);
for M = [0 1 2]
for i = 1:length(Lv)
L = Lv(i);
ODE = @(x,y) [ y(2); y(3); y(2)^2 - y(1)*y(3) - A^2 + (M+Da)*(y(2)-A) - L*y(4);
y(5); -Pr*( y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + s*y(4) )
y(7); -Le*Pr*(y(1)*y(7) - Kc*y(6)) + (Nt/Nb)*Pr*( y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + s*y(4) )];
BC = @(ya,yb)[ya(1); ya(2)-1; ya(5)-B*(ya(4)-1); Nb*ya(7)+Nt*ya(5); yb(2)-A; yb([4,6])]; xa = 0; xb = 6;
x = linspace(xa,xb,100); solinit = bvpinit(x,[0 1 0 1 0 1 0]); sol = bvp5c(ODE,BC,solinit); S = deval(sol,x);
figure(1),surf(x,Lv,[1;1]*S(2,:));hold on;xlabel('\bfx','Color','blue'); ylabel('\bfL','Color','blue');
zlabel '\bfS(2,:)';
end
end
%%% Want to draw surf plot of S(2,:) with 'x' as x-axis variation, 'L' as y-axis variation
0 个评论
采纳的回答
Voss
2023-7-25
Like this?
A = 1; M = 1; Da = 0.1; L = 0.1; Pr = 1; Nb = 0.1; Nt = 0.5; s = 0.5; Le = 2; Kc = 1;B = 0.5;
xa = 0; xb = 6;
Lv = linspace(-2,2,100);
x = linspace(xa,xb,100);
S_all = zeros(numel(Lv),numel(x));
for M = [0 1 2]
for i = 1:numel(Lv)
L = Lv(i);
ODE = @(x,y) [ y(2); y(3); y(2)^2 - y(1)*y(3) - A^2 + (M+Da)*(y(2)-A) - L*y(4);
y(5); -Pr*( y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + s*y(4) )
y(7); -Le*Pr*(y(1)*y(7) - Kc*y(6)) + (Nt/Nb)*Pr*( y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + s*y(4) )];
BC = @(ya,yb)[ya(1); ya(2)-1; ya(5)-B*(ya(4)-1); Nb*ya(7)+Nt*ya(5); yb(2)-A; yb([4,6])];
solinit = bvpinit(x,[0 1 0 1 0 1 0]);
sol = bvp5c(ODE,BC,solinit);
S = deval(sol,x);
S_all(i,:) = S(2,:);
end
figure()
surf(x,Lv,S_all);
hold on;
xlabel('\bfx','Color','blue');
ylabel('\bfL','Color','blue');
zlabel('\bfS(2,:)');
title(sprintf('M = %d',M));
end
0 个评论
更多回答(1 个)
Mrutyunjaya Hiremath
2023-7-25
To create the surface plot for the given code, you can use the MATLAB 'surf' function inside the loop. However, you need to be careful about the input arguments to the 'surf' function to ensure that the data is correctly plotted.
- Here's the modified code with the surf plot:
A = 1; M = 1; Da = 0.1; Pr = 1; Nb = 0.1; Nt = 0.5; s = 0.5; Le = 2; Kc = 1; B = 0.5;
Lv = linspace(-2, 2, 100);
figure(1);
hold on;
xlabel('\bfx', 'Color', 'blue');
ylabel('\bfL', 'Color', 'blue');
zlabel('\bfS(2,:)');
for M = [0, 1, 2]
for i = 1:length(Lv)
L = Lv(i);
ODE = @(x, y) [ y(2); y(3); y(2)^2 - y(1)*y(3) - A^2 + (M + Da)*(y(2) - A) - L*y(4);
y(5); -Pr*(y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + s*y(4))
y(7); -Le*Pr*(y(1)*y(7) - Kc*y(6)) + (Nt/Nb)*Pr*(y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + s*y(4))];
BC = @(ya, yb) [ya(1); ya(2) - 1; ya(5) - B*(ya(4) - 1); Nb*ya(7) + Nt*ya(5); yb(2) - A; yb([4, 6])];
xa = 0; xb = 6;
x = linspace(xa, xb, 100);
solinit = bvpinit(x, [0, 1, 0, 1, 0, 1, 0]);
sol = bvp5c(ODE, BC, solinit);
S = deval(sol, x);
surf(x, Lv(i)*ones(size(x)), [1; 1]*S(2, :));
end
end
hold off;
- This code should create a surface plot showing the variation of S(2,:) with respect to x and L for different values of M. The surf function is used to plot the data, and we use Lv(i)*ones(size(x)) to create a meshgrid for the surf plot, with Lv(i) repeated for the entire x range.
2 个评论
Mrutyunjaya Hiremath
2023-7-25
clc;
close all;
clear all;
A = 1; M = 1; Da = 0.1; Pr = 1; Nb = 0.1; Nt = 0.5; s = 0.5; Le = 2; Kc = 1; B = 0.5;
Lv = linspace(-2, 2, 100);
figure(1);
hold on;
xlabel('\bfx', 'Color', 'blue');
ylabel('\bfL', 'Color', 'blue');
zlabel('\bfS(2,:)');
for M_val = [0, 1, 2]
for i = 1:length(Lv)
L = Lv(i);
ODE = @(x, y) [ y(2); y(3); y(2)^2 - y(1)*y(3) - A^2 + (M_val + Da)*(y(2) - A) - L*y(4);
y(5); -Pr*(y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + s*y(4))
y(7); -Le*Pr*(y(1)*y(7) - Kc*y(6)) + (Nt/Nb)*Pr*(y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + s*y(4))];
BC = @(ya, yb) [ya(1); ya(2) - 1; ya(5) - B*(ya(4) - 1); Nb*ya(7) + Nt*ya(5); yb(2) - A; yb([4, 6])];
xa = 0; xb = 6;
x = linspace(xa, xb, 100);
solinit = bvpinit(x, [0, 1, 0, 1, 0, 1, 0]);
sol = bvp5c(ODE, BC, solinit);
S = deval(sol, x);
% Use meshgrid to create a 2D grid of x and Lv(i) values
[X, Y] = meshgrid(x, Lv(i)*ones(size(x)));
% Reshape [1; 1]*S(2, :) to match the size of the grid
Z = repmat([1]*S(2, :), size(X, 1), 1);
surf(X, Y, Z);
end
end
hold off;
% Enable interactive rotation of the 3D plot
rotate3d on;
% Set the initial view to a 45-degree rotation
view(45, 45);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!