필터 지우기
필터 지우기

surf plot is required

조회 수: 4 (최근 30일)
MINATI PATRA
MINATI PATRA 2023년 7월 25일
댓글: Mrutyunjaya Hiremath 2023년 7월 25일
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
Error using surf
Data dimensions must agree.
%%% Want to draw surf plot of S(2,:) with 'x' as x-axis variation, 'L' as y-axis variation

채택된 답변

Voss
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
Warning: Unable to meet the tolerance without using more than 1428 mesh points.
The last mesh of 294 points and the solution are available in the output argument.
The maximum error is 256.798, while requested accuracy is 0.001.
Warning: Unable to meet the tolerance without using more than 1428 mesh points.
The last mesh of 294 points and the solution are available in the output argument.
The maximum error is 85.7775, while requested accuracy is 0.001.

추가 답변 (1개)

Mrutyunjaya Hiremath
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
MINATI PATRA
MINATI PATRA 2023년 7월 25일
@ Mrutyunjaya Hiremath
After running the code the following ERROR is coming:
Error using surf
Data dimensions must agree.
Error (line 13)
surf(x, Lv(i)*ones(size(x)), [1; 1]*S(2, :));
Mrutyunjaya Hiremath
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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by