Please help me to run this simple relation

I want to draw relation between T ( y-axis) and x ( x-axis) with change parameter B1.
Constant:
B2=0.01;B4=0.1;
vector
Parameter
B1=0.1:0.1:0.5

Answers (1)

Probably the easiest way to do this is with a surf plot. Here, I combined it with a contour plot as well, using the surfc function.
Try something like this --
B2 = 0.01;
B4 = 0.1;
B1=0.1:0.1:0.5;
x = 0:0.01:1;
[xm,B1m] = ndgrid(x,B1);
T = (B1m-B2)./(3*B4) .* (1 + exp(xm));
figure
surfc(xm, B1m, T)
colormap(turbo)
colorbar
xlabel('x')
ylabel('B1')
zlabel('T')
.

5 Comments

T K
T K on 14 Apr 2026
Edited: T K on 14 Apr 2026
I want to draw in 2 Dimension X-axis is X Y-axis is T Parameter is B1
I missed the fact that the first term was negated earlier. Corrected here.
Here you go ---
B2 = 0.01;
B4 = 0.1;
B1=0.1:0.1:0.5;
x = 0:0.01:1;
[xm,B1m] = ndgrid(x,B1);
T = (B1m-B2)./(3*B4) .* (exp(xm) - 1);
figure
plot(x, T)
grid
xlabel('x')
ylabel('T')
title('$T(x,B1) = \frac{(B1-B2)}{3B4}(e^x-1)$', Interpreter='LaTeX')
legend(compose('B1 = %.1f', B1), Location='best')
figure
surfc(xm, B1m, T)
colormap(turbo)
colorbar
xlabel('x')
ylabel('B1')
zlabel('T')
title('$T(x,B1) = \frac{(B1-B2)}{3B4}(e^x-1)$', Interpreter='LaTeX')
.
T K
T K on 14 Apr 2026
Edited: T K on 14 Apr 2026
Oh,thanks alot professor Star. Finally, what is the importance of [xm,B1m] = ndgrid(x,B1) in this code ??
My pleasure!
That assignment creates matrices of the same sizes for 'x' and 'B1', creating 'xm' (x matrix) and 'B1m' (B1 matrix). The matrices are important because they make the calculations easier, eliminating explicit loops that would otherwise be required.
The 'T' calculation
T = (B1m-B2)./(3*B4) .* (exp(xm) - 1);
then uses them to produce its own matrix, with dimensions matching the original matrices. That makes the plotting easier.
The 'dot operators force array (element-wise) division (./) and multiplication (.*) rather than matrix division and multiplication.
.
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

Categories

Find more on Surfaces, Volumes, and Polygons in Help Center and File Exchange

Tags

Asked:

on 13 Apr 2026

Commented:

on 14 Apr 2026

Community Treasure Hunt

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

Start Hunting!