How to make dashed lines from dotted line commad whenever I changed '--' from ':'. I got solid lines intead of dashed lines

6 views (last 30 days)
The code works fine but I want to changes dotted lines into dashed line (1st line solid and other lines in dashed form). I tried dashed line command '--' but I got Solid lines instead of dashed lines. I need help in this regard
function
clc
clf
clear all
close all
for i=1:5
Pr=1;
lambda=0.5;
k=[1 1.5 3 8 20];
We=0.1;
M=0.5;
C=0.5;
infinity=3;
solinit = bvpinit(linspace(0,infinity,100),[0 0 1 1 C 0 0 0]);
options = bvpset('stats','on');
sol = bvp4c(@ex8ode,@ex8bc,solinit,options, Pr, lambda, k(:,i), We, M, C);
eta = sol.x;
f = sol.y;
n=['-',':',':',':',':'];
j=['k','y','b','g','r'];
fprintf('\n');
plot(eta,f(2,:),n(:,i),'linewidth',1, 'color',j(:,i));
hold on
end
xlabel('\eta');ylabel('f^\prime(\eta)');
legend('K=1','K=1.5','K=3','K=8','K=20')
% --------------------------------------------------------------------------
function dfdeta = ex8ode(eta,f, Pr, lambda, k, We, M, C)
%EX8ODE ODE function for velocity profile.
dfdeta = [ f(2)
f(3)
(1/(1+We*f(3)))*(f(2).^2-f(1).*f(3)-f(4).*f(3)+M*f(2)+lambda*f(7)+(1/k)*f(2))
f(5)
f(6)
(1/(1+We*f(6)))*(f(5).^2-f(1).*f(6)-f(4).*f(6)+M*f(5)+(1/k)*f(5))
f(8)
-Pr*(f(1).*f(8)+f(4).*f(8))
];
% --------------------------------------------------------------------------
function res = ex8bc(f0,finf,Pr, lambda, k, We, M, C)
%EX8BC Boundary for velocity profile of williamson fluid.
res = [f0(1)
f0(4)
f0(7)-1
f0(2)-1
f0(5)-C
finf(2)
finf(5)
finf(7)
];
  8 Comments
Walter Roberson
Walter Roberson on 23 Jan 2021
GhulamDastgeerVariationForK
The solution was obtained on a mesh of 100 points. The maximum residual is 2.649e-04. There were 3898 calls to the ODE function. There were 83 calls to the BC function.
The solution was obtained on a mesh of 100 points. The maximum residual is 3.088e-04. There were 3998 calls to the ODE function. There were 83 calls to the BC function.
The solution was obtained on a mesh of 100 points. The maximum residual is 7.754e-05. There were 3798 calls to the ODE function. There were 83 calls to the BC function.
The solution was obtained on a mesh of 100 points. The maximum residual is 6.246e-04. There were 2996 calls to the ODE function. There were 58 calls to the BC function.
The solution was obtained on a mesh of 80 points. The maximum residual is 2.262e-05. There were 4114 calls to the ODE function. There were 85 calls to the BC function.
function GhulamDastgeerVariationForK
for i=1:5
Pr=1;
lambda=0.5;
k=[1 1.5 3 8 20];
We=0.1;
M=0.5;
C=0.5;
infinity=3;
solinit = bvpinit(linspace(0,infinity,100),[0 0 1 1 C 0 0 0]);
options = bvpset('stats','on');
sol = bvp4c(@ex8ode,@ex8bc,solinit,options, Pr, lambda, k(:,i), We, M, C);
eta = sol.x;
f = sol.y;
n=['-',':',':',':',':'];
j=['k','y','b','g','r'];
fprintf('\n');
plot(eta,f(2,:),n(:,i),'linewidth',1, 'color',j(:,i));
hold on
end
xlabel('\eta');ylabel('f^\prime(\eta)');
legend('K=1','K=1.5','K=3','K=8','K=20')
end
% --------------------------------------------------------------------------
function dfdeta = ex8ode(eta,f, Pr, lambda, k, We, M, C)
%EX8ODE ODE function for velocity profile.
dfdeta = [ f(2)
f(3)
(1/(1+We*f(3)))*(f(2).^2-f(1).*f(3)-f(4).*f(3)+M*f(2)+lambda*f(7)+(1/k)*f(2))
f(5)
f(6)
(1/(1+We*f(6)))*(f(5).^2-f(1).*f(6)-f(4).*f(6)+M*f(5)+(1/k)*f(5))
f(8)
-Pr*(f(1).*f(8)+f(4).*f(8))
];
end
% --------------------------------------------------------------------------
function res = ex8bc(f0,finf,Pr, lambda, k, We, M, C)
%EX8BC Boundary for velocity profile of williamson fluid.
res = [f0(1)
f0(4)
f0(7)-1
f0(2)-1
f0(5)-C
finf(2)
finf(5)
finf(7)
];
end

Sign in to comment.

Answers (1)

Harshavardhan
Harshavardhan on 26 Jun 2025
The lines in your MATLAB plot are appearing solid instead of dashed due to how you're indexing the line styles and colors in your code. MATLAB treats n(:,i) and j(:,i) as indexing columns of a character array. Since '--' is two characters, MATLAB stores it as a 2D character array, and n(:,i) returns a column vector of characters, not a valid line style string.
To fix this:
  • Use cell arrays instead of character arrays
  • Update “plot”
Here is the updated code:
n={'-','--','--','--','--'};
j={'k','y','b','g','r'};
fprintf('\n');
plot(eta,f(2,:),n{i},'linewidth',1, 'color',j{i});
For more information on cell arrays refer to the link below:

Categories

Find more on Polynomials 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!