plotting Graph in 3D help

조회 수: 4 (최근 30일)
Fareeha
Fareeha 2024년 7월 4일
댓글: Umar 2024년 7월 30일
basic()
function basic
K=0.2; n=0.3; lam=0.1;
%Defining parameters
sol1 = bvpinit(linspace(0,6,300),[0 0 0 0 0]);
sol = bvp4c(@bvp2D, @bc2D, sol1);
x = sol.x;
y = sol.y;
%%% Plotting of the velocity
figure (1)
plot(x, y(2, :) ,'linewidth', 1.5);
hold on
xlabel('\eta', 'fontweight', 'bold', 'fontsize', 16)
ylabel('f^{\prime}(\eta)', 'fontweight', 'bold', 'fontsize', 16)
%% Residual of the boundary conditions
function residual = bc2D(y0, yinf)
residual=[y0(1); y0(2) - 1; y0(4)+n*y0(3); yinf(2)-lam; yinf(4)];
end
%% System of First Order ODEs
function yvector = bvp2D(~,y)
yy1 =(1/(1+K))*(-y(1)*y(3)+y(2)^2-K*y(5)-lam^2);
yy2 =(2/(2+K))*(-y(1)*y(5)+y(2)*y(4)+K*(2*y(4)+y(3)));
yvector = [y(2);y(3);yy1; y(5); yy2];
end
end
i want to plot this graph in 3D, how can I?

채택된 답변

Umar
Umar 2024년 7월 4일
편집: Walter Roberson 2024년 7월 29일
Hi Fareeha,
You asked, i want to plot this graph in 3D, how can I?
In order to do that, you can use plot3 function to achieve your goal. For more information on this function, please refer to
Let me know if this answers your question.
  댓글 수: 12
Umar
Umar 2024년 7월 6일

Hi Fareeha,

To fix the error, ensure that the input matrix Z passed to the contourf function is at least a 2x2 matrix. Here's an example to demonstrate how to fix the error:

% Create sample data

x = 1:5; y = 1:5; [X, Y] = meshgrid(x, y);

% Example data, replace with your own data

Z = peaks(5);

% Plot the contour

contourf(X, Y, Z, 'LineWidth', 1.5);

Please see attached plot.

In this example, X and Y are 2D matrices created using meshgrid, and Z is a sample 5x5 matrix. By ensuring that Z is a valid 2D matrix, the error should be resolved when calling contourf.

Let me know if you need further assistance or help.

Fareeha
Fareeha 2024년 7월 7일
편집: Fareeha 2024년 7월 7일
@Umar thank you, i have just used z=peak(); in my code and able to generate contour.. I am attaching figure for reference.. can you tell how to check whether i am getting right figure?
can i use Z=peak(); in my code?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Umar
Umar 2024년 7월 7일
Hi Fareeha,
In response to your first question, to confirm if you are getting the right figure after using the "z=peak();" function in your code, you can employ various methods. One common approach is to visually inspect the output or result generated by the function to see if it aligns with your expectations. This could involve plotting or displaying the figure to ensure it matches what you anticipate. Furthermore, you can compare the output obtained from "z=peak();" with known values or expected outcomes to validate its accuracy. By verifying against established benchmarks or test cases, you can assess if the figure produced by the function is correct. Also, bear in mind that in MATLAB, the function z=peak(); is typically used to generate a sample data matrix that can be visualized as a contour plot. When you use this function, it creates a 49x49 matrix with peak values that form a peak in the center. If you want to generate the correct contour plot using this data, you do not necessarily have to modify your code. However, it is important to ensure that you are using the correct variable name when accessing the data matrix. In this case, if you initially used z=peak(); to store the data matrix, you should continue to reference it as z in your code.
Regarding your second query about using "Z=peak();" instead of "z=peak();", it typically depends on the programming language or environment you are working in. In some languages, variable names are case-sensitive, meaning that "z" and "Z" would be treated as distinct variables. Therefore, using "Z=peak();" might create a new variable "Z" rather than updating the existing variable "z". To ensure consistency and prevent potential errors, it is advisable to stick to a consistent naming convention for variables within your code. If you intend to update the original variable "z" with a new value from "peak();", it is recommended to use the same case for consistency.
Hope this answers all your questions.
  댓글 수: 8
Fareeha
Fareeha 2024년 7월 30일
@Umar i tried it and now i got this error:
Error using stream2 (line 46)
U,V must all be size 2x2 or greater.
Error in streamline (line 62)
verts = stream2(x,y,u,v,sx,sy,options);
Error in contour_plot_Magnetic_C (line 34)
streamline(X, Y, reshaped_u, reshaped_v, 0, 0);
i am using streamline function neither verts nor stream2.. then why i am getting this errror?
Umar
Umar 2024년 7월 30일
@Fareeha,
Could you please share your code snippet that is causing these errors. Thx

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by