Having problem with fixing the issue

Hi guys.
Here are some weird functions which I'm trying to plot. I am a novice and did a few more graphs smoothly, however, this one is a bit more tricky. Seems like I'm having some problem with sytax or so. Looking for possible help.
Thanks
Waqar
x = linspace(0,5);
y1=(-15.17006719-10.19830710*I)*((-.3397894164*2^(2/3)-2.584061447*2^(1/3)+15.96541878)*hypergeom([4.811602425], [6.811602422], -6.723676050*exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x))+(-11.74363984+.3386696355*2^(2/3)+.9999999998*2^(1/3))*exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x)*hypergeom([5.811602424], [7.811602422], -6.723676050*exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x)))*(-exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x))^4.811602421;
plot(x,y1,'-.','Color','[0 0 0]','DisplayName','\fontname {Helvetica} \fontsize{20} \kappa;=0.1, s=-0.1','LineWidth', 2.0)
xlabel('\fontname{Times New Roman} Values of x', 'FontSize', 22)
ylabel('\fontname{Times New Roman} Velocity Profile','FontSize',22')
hold on
y2=(-41.76167543-277.1087639*I)*(-exp(-.6942370405*x))^4.547612589*((0.6153550094e-1*2^(2/3)-2.648960805*2^(1/3)+5.574199339)*hypergeom([4.547612586], [6.547612585], -8.572516010*exp(-.6942370405*x))+(-4.013958993+.1566293604*2^(2/3)+1.000000000*2^(1/3))*exp(-.6942370405*x)*hypergeom([5.547612584], [7.547612587], -8.572516010*exp(-.6942370405*x)));
plot(x,y2, ':','Color','[0 0 0]','DisplayName','\fontname {Helvetica} \fontsize{20} \kappa;=0.1, s=-0.3','LineWidth', 2.0)
y3=(8.054902998+2.463354463*I)*(-exp(-.8175736472*x))^3.90552941*((-2.482855195*2^(1/3)+14.73597244-.2149702398*2^(2/3))*hypergeom([3.905529413], [5.905529410], -5.761721393*exp(-.8175736472*x))+(-10.71834160+.4453954039*2^(2/3)+1.000000000*2^(1/3))*exp(-.8175736472*x)*hypergeom([4.905529411], [6.905529412], -5.761721393*exp(-.8175736472*x)));
plot(x,y3,'--','Color','[0 0 0]','DisplayName','\fontname {Helvetica} \fontsize{20} \kappa;=0.2, s=-0.1','LineWidth', 2.0)
y4=(-12.45342459+98.65993194*I)*((5.141075166+.1059158437*2^(2/3)-2.574899769*2^(1/3))*hypergeom([3.460032462], [5.460032468], -7.288618279*exp(-.7424204657*x))+(-3.715037183+.1994232887*2^(2/3)+1.000000000*2^(1/3))*exp(-.7424204657*x)*hypergeom([4.460032463], [6.460032464], -7.288618279*exp(-.7424204657*x)))*(-exp(-.7424204657*x))^3.460032466;
plot(x,y4,'Color','[0 0 0]','DisplayName','\fontname {Helvetica} \fontsize{20} \kappa;=0.2, s=-0.3','LineWidth', 2.0)
ax = gca;
ax.FontSize = 19;
set(gca,'XLim',[0 5]);
set(gca,'YLim',[0 1]);
set(gca,'XTick',[0 1 2 3 4 5])
box off
hold off
lgd = legend;
lgd.FontSize = 20;
lgd.Title.String = 'Values of \lambda';
legend;
legend('boxoff')

5 commentaires

Walter Roberson
Walter Roberson le 10 Mai 2020
Is it or is it ?
Ke Le
Ke Le le 10 Mai 2020
Dear Walter, it is \lambda=\zeta^(2/3).
The only thing I see obviously wrong is that
xlabel('\fontname{Times New Roman} Values of \x', 'FontSize', 22)
should be using something other than \x
I can make a guess that I is probably sqrt(-1)
You are generating complex values regardless of whether I is sqrt(-1) or is real valued. Look at your
(-exp(-.6942370405*eta))^4.547612589
exp(something) is going to be positive for real-valued eta, and - of that is going to be negative, and when that negative is raised to a fraction such as 4.54whatever then you are going to get a complex value.
Ke Le
Ke Le le 10 Mai 2020
That is very true. So, it would mean I should go back to the other tools (Maple, Mathematica etc) beacsue I can't do it here in Matlab.
Maple would generate a complex number in that situation as well.
eta := 2;
eta := 2
(-exp(-0.6942370405*eta))^4.547612589;
-0.0002697804212 + 0.001790122601 I

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 10 Mai 2020
lambda = zeta.^(2/3)
However if you need negative values to have positive results, then
lambda = zeta.^2.^(1/3)

4 commentaires

Ke Le
Ke Le le 10 Mai 2020
In fact, what I'm trying is to convert these longer function into Matlab language from Maple, where I see no issue. In Matlab it shows some sort of this issue:
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the
second matrix. To perform elementwise multiplication, use '.*'.
In MATLAB, * is the algebraic matrix multiplication operator, inner product. You are working with row vectors and asking to * those row vectors, which is a dimension error for inner product. You should convert all of your * to .* and all of your ^ to .^ (though you can use * or ^ if you are certain the parts are scalar.) For example,
y1=(-15.17006719-10.19830710*I)*((-.3397894164*2^(2/3)-2.584061447*2^(1/3)+15.96541878)*hypergeom([4.811602425], [6.811602422], -6.723676050*exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x))+(-11.74363984+.3386696355*2^(2/3)+.9999999998*2^(1/3))*exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x).*hypergeom([5.811602424], [7.811602422], -6.723676050*exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x))).*(-exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x)).^4.811602421;
Ke Le
Ke Le le 11 Mai 2020
That's perfect for the first expression. Is there any further explanation for dimension error issue? I can't actually work out with rest of the three expressions.
In the below, the character vectors for y1_, y2_, y3_, y4_ are exactly the formulas you had in your code. The below code automatically vectorizes the formulas so there will not be any mistakes.
I = 1i;
y1_ = '(-15.17006719-10.19830710*I)*((-.3397894164*2^(2/3)-2.584061447*2^(1/3)+15.96541878)*hypergeom([4.811602425], [6.811602422], -6.723676050*exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x))+(-11.74363984+.3386696355*2^(2/3)+.9999999998*2^(1/3))*exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x)*hypergeom([5.811602424], [7.811602422], -6.723676050*exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x)))*(-exp(-(-.3666666667+.6297451706*2^(2/3)+.1067451175*2^(1/3))*x))^4.811602421';
y2_ = '(-41.76167543-277.1087639*I)*(-exp(-.6942370405*x))^4.547612589*((0.6153550094e-1*2^(2/3)-2.648960805*2^(1/3)+5.574199339)*hypergeom([4.547612586], [6.547612585], -8.572516010*exp(-.6942370405*x))+(-4.013958993+.1566293604*2^(2/3)+1.000000000*2^(1/3))*exp(-.6942370405*x)*hypergeom([5.547612584], [7.547612587], -8.572516010*exp(-.6942370405*x)))';
y3_ = '(8.054902998+2.463354463*I)*(-exp(-.8175736472*x))^3.90552941*((-2.482855195*2^(1/3)+14.73597244-.2149702398*2^(2/3))*hypergeom([3.905529413], [5.905529410], -5.761721393*exp(-.8175736472*x))+(-10.71834160+.4453954039*2^(2/3)+1.000000000*2^(1/3))*exp(-.8175736472*x)*hypergeom([4.905529411], [6.905529412], -5.761721393*exp(-.8175736472*x)))';
y4_ = '(-12.45342459+98.65993194*I)*((5.141075166+.1059158437*2^(2/3)-2.574899769*2^(1/3))*hypergeom([3.460032462], [5.460032468], -7.288618279*exp(-.7424204657*x))+(-3.715037183+.1994232887*2^(2/3)+1.000000000*2^(1/3))*exp(-.7424204657*x)*hypergeom([4.460032463], [6.460032464], -7.288618279*exp(-.7424204657*x)))*(-exp(-.7424204657*x))^3.460032466';
y1 = str2fun(['@(x,I)', vectorize(y1_)]);
y2 = str2fun(['@(x,I)', vectorize(y2_)]);
y3 = str2fun(['@(x,I)', vectorize(y3_)]);
y4 = str2fun(['@(x,I)', vectorize(y4_)]);
x = linspace(0,5);
plot(x,y1(x,I),'-.','Color','[0 0 0]','DisplayName','\fontname {Helvetica} \fontsize{20} \kappa;=0.1, s=-0.1','LineWidth', 2.0)
xlabel('\fontname{Times New Roman} Values of x', 'FontSize', 22)
ylabel('\fontname{Times New Roman} Velocity Profile','FontSize',22')
hold on
plot(x,y2(x,I), ':','Color','[0 0 0]','DisplayName','\fontname {Helvetica} \fontsize{20} \kappa;=0.1, s=-0.3','LineWidth', 2.0)
plot(x,y3(x,I),'--','Color','[0 0 0]','DisplayName','\fontname {Helvetica} \fontsize{20} \kappa;=0.2, s=-0.1','LineWidth', 2.0)
plot(x,y4(x,I),'Color','[0 0 0]','DisplayName','\fontname {Helvetica} \fontsize{20} \kappa;=0.2, s=-0.3','LineWidth', 2.0)
ax = gca;
ax.FontSize = 19;
set(gca,'XLim',[0 5]);
set(gca,'YLim',[0 1]);
set(gca,'XTick',[0 1 2 3 4 5])
box off
hold off
lgd = legend;
lgd.FontSize = 20;
lgd.Title.String = 'Values of \lambda';
legend;
legend('boxoff')

Connectez-vous pour commenter.

Ke Le
Ke Le le 12 Mai 2020

0 votes

Great. Thank you very much

4 commentaires

Walter Roberson
Walter Roberson le 12 Mai 2020
You accepted your own Answer, which implies that you came up with a different solution that works for you when the other Answers do not. It would be beneficial for you to post that alternative solution so that people could study it and see how your needs turned out to differ from what volunteers came up with.
Ke Le
Ke Le le 21 Mai 2020
Walter, there's till some running issue with your code. What I did:
  1. Remove [ ] in Hypergeometric to () or even leave it without ()
  2. Replace * and ^ with .* and .^ (you said it earlier and it helped)
  3. Ignore the imaginary part in every expression
Walter Roberson
Walter Roberson le 21 Mai 2020
[number] asks MATLAB to build a vector that contains only the number. But in MATLAB every scalar is the exact same thing as a vector of length 1, so as far as MATLAB is concerned, [123] has an identical run-time representation as 123 without [] . The only difference is small run-time penalty.
The y1_ etc version automatically vectorizes so that you do not need to make the changes yourself (potentially missing some of them)
Ignoring the imaginary part is an important change though.
Ke Le
Ke Le le 8 Juin 2020
Very true. Thanks

Connectez-vous pour commenter.

Question posée :

le 10 Mai 2020

Commenté :

le 8 Juin 2020

Community Treasure Hunt

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

Start Hunting!

Translated by