"fsolve" doesn't work for system nonlinear equation - matlab

I have these equations:
syms pm pr teta s
A1 = -2 * b1 * pm + 2 * b2 * pr + b * teta + (1-t) * s + (1-p) * a + c * (b1 - b2);
A2 = 2 * b2 * pm + 2 * b1 * pr + (1-b) * teta + t * s + p * a + c * (b1 - b2);
A3 = b * pm + (1-b) * pr - n * teta - c;
A4 = (1-t) * pm + t * pr - k * s - c;
eqns = [A1,A2,A3,A4];
F=#(pm, pr, teta, s) [A1
A2
A3
A4];
x0 = [10, 10, 10, 10];
fsolve(F, x0)
How I can solve them?
(When I use fsolve, it shows this error: FSOLVE requires all values returned by functions to be of data type double)

Since you tagged Mathematica
A1 = -2*b1*pm + 2*b2*pr + b*teta + (1 - t)*s + (1 - p)*a + c*(b1 - b2);
A2 = 2*b2*pm + 2*b1*pr + (1 - b)*teta + t*s + p*a + c*(b1 - b2);
A3 = b*pm + (1 - b)*pr - n*teta - c;
A4 = (1 - t)*pm + t*pr - k*s - c;
FullSimplify[Solve[{A1 == 10, A2 == 10, A3 == 10, A4 == 10}, {pm, pr, teta, s}]]
pm -> ((k ((-1 + b)^2 + 2 b1 n) + n t^2) (b (10 + c) k +
n (10 + c + 10 k - a k - b1 c k + b2 c k +
a k p - (10 + c) t)) + ((-1 + b) (10 + c) k +
k n (-10 + b1 c - b2 c + a p) - (10 + c) n t) (b k - b^2 k +
n (2 b2 k + t - t^2)))/(k n (1 - 2 b1 k + b^2 (1 + 4 b2 k) +
2 (b1 - 2 (b1^2 + b2^2) k) n - 2 t -
4 (b1 + b2) n t + (1 + 4 b2 n) t^2 +
2 b (-1 + 2 b1 k - 2 b2 k + t)))
pr -> (c +
b^2 (10 + c - (-20 + a + 2 b1 c - 2 b2 c) k) + 2 b1^2 c k n -
b2 (20 + c - 2 (-10 + a) k + 2 b2 c k) n - a (1 + 2 b2 k) n p -
2 b1 k (10 + c + n (10 - a p)) + 10 (1 + n - 2 t) -
c (2 + b2 n) t +
n (-30 + a + 20 b2 + a p) t + (10 + c - (-20 + a) n +
2 b2 c n) t^2 - b1 n (c + 20 t + c t (-1 + 2 t)) +
b (k (-10 + a + 20 b1 - 20 b2 - a p) + 20 (-1 + t) +
c (-2 + 3 b1 k - 3 b2 k + 2 t)))/(1 - 2 b1 k +
b^2 (1 + 4 b2 k) + 2 (b1 - 2 (b1^2 + b2^2) k) n - 2 t -
4 (b1 + b2) n t + (1 + 4 b2 n) t^2 +
2 b (-1 + 2 b1 k - 2 b2 k + t))
teta -> (10 - 20 b2 - b2 c -
20 b2 k + 2 a b2 k + 40 b2^2 k + 2 b2^2 c k +
2 b1^2 (20 + 3 c) k - a p -
2 a b2 k p + (-30 + 3 b2 (20 + c) + a (1 + p)) t - (-20 + a +
2 b2 (20 + c)) t^2 +
b (-10 - 4 b1^2 c k + a p +
b1 (20 + 40 k - 2 a k + c (3 + 4 b2 k - 2 t)) + 20 t - a t +
b2 (20 + c - 2 a k + 4 a k p - 2 (20 + c) t)) +
b1 (2 k (-10 + a p) + 20 (-1 + t) + c (-3 + (5 - 2 t) t)))/(1 -
2 b1 k + b^2 (1 + 4 b2 k) + 2 (b1 - 2 (b1^2 + b2^2) k) n - 2 t -
4 (b1 + b2) n t + (1 + 4 b2 n) t^2 +
2 b (-1 + 2 b1 k - 2 b2 k + t))
s -> (20 b1 + b1 c - b2 c -
2 b^2 (-10 + b1 c + b2 (20 + c)) + 20 b1 n + 40 b1^2 n -
20 b2 n + 40 b2^2 n + 2 b1^2 c n + 4 b1 b2 c n +
2 b2^2 c n - (b1 - b2) (20 + c) t +
4 b1 (-10 + b1 c - b2 c) n t - 10 (-1 + 2 b2 + t) +
a (-1 - b^2 - 2 b1 n + p + 2 (b1 + b2) n p + t - p t +
2 n (b1 + b2 - 2 b2 p) t - b (-2 + p + t)) +
b (-(-10 + b2 (20 + c)) (-3 + 2 t) + b1 (-20 + c - 2 c t)))/(1 -
2 b1 k + b^2 (1 + 4 b2 k) + 2 (b1 - 2 (b1^2 + b2^2) k) n - 2 t -
4 (b1 + b2) n t + (1 + 4 b2 n) t^2 +
2 b (-1 + 2 b1 k - 2 b2 k + t))

Related

how to solve subscript out of range in qbasic

I am in big problem in solving a code essential for me, and I need the solution as soon as possible
in fact, I have little knowledge of programming in basic
I have a problem with this code.
I have an equation, and I use this code to solve this equation
when I run the program
this error appears
subscript out of range
is there any solution to this problem
0 Print "******** impact *******"
20 Print "____________"
30 Print "this programs is used to solve impact integral"
40 Print "equation of simply supported slab to "
50 Print "optain the following"
60 Print " (1) force _time history"
70 Print " (2) central deflection - time history"
80 Print "-----------------"
90 Print "input data:"
100 Print " (1) FUNDAMENTAL NATURAL FREQUANCY (RAD/SEC)--- W1"
110 Print " (2) STRIKER MASS (KG.) ----- Mst"
120 Print " (3) MASS OF SLAB (KG)---- Ms"
130 Print " (4) hertz constant (n/m^1.5)----k"
140 Print " (5) STRICKER VELOCITY (M/S)----Vo"
150 Print " (6) NUMBER OF MODES----N"
160 Print "_________"
170 Input " W11, MST, MS, K, VO, N", W11, MST, MS, K, VO, N
180 Print "W1="; W11; "RAD/SEC"
190 Print "MST="; MST; "KG"
200 Print "MS="; MS; "KG"
210
220 Print " K = "; K; "N/M^1.5"
230 Print STANDARD
240 Print "VO="; VO; "M/S"
241 Print " N = "; N
250 Print
260 Print
270 K1 = K
280 V = VO
290 W1 = W11 / 2
300 TINF = 2.94 * (MST / (.8 * K1 * V ^ .5)) ^ .4 * 1000
310 DT = TINF / 10
320 M = 20
330 DT = PROUND(DT, 0)
340 DT = DT / 1000
350 M = 20
360 Option Base 1
370 Dim W(11, 11), Z(11, 11), F(30), D(30), BM(30), SH(30), A(30), T(30), DF(30), S(11, 11, 30), C(11, 11, 30)
380 ReDim W(N, N), Z(N, N)
390 For I = 1 To N Step 2
400 For K = 1 To N Step 2
410 W(K, I) = W1 * (I ^ 2 + K ^ 2)
420 Z(K, I) = W(K, I) * DT
430 Next K
440 Next I
450 ReDim F(M), D(M), A(M), T(M), DF(M), BM(M), SH(M), S(N, N, M), C(N, N, M)
460 F(1) = D(1) = A(1) = T(1) = 0
470 For I = 1 To N Step 2
480 For K = 1 To N Step 2
490 S(K, I, 1) = C(K, I, 1) = 0
500 Next K
510 Next I
520 B1 = 0
530 For I = 1 To N Step 2
540 For K = 1 To N Step 2
550 B1 = B1 + (1 - Sin(Z(K, I)) / Z(K, I)) / W(K, I) ^ 2
560 Next K
570 Next I
580 B = -DT ^ 2 / (6 * MST) - 4 * B1 / MS
590 VE = 0
600 For I = 2 To M
610 T(I) = (I - 1) * DT
620 GM = 0
630 If VE = 1 Then 970
640 For J = 2 To I
650 GM = GM + F(J - 1)
660 Next J
670 AA = 0
680 For J = 1 To N Step 2
690 For K = 1 To N Step 2
700 FF = F(I - 1) * (Sin(Z(K, J)) / Z(K, J) - Cos(Z(K, J))) / W(K, J)
710 AA = AA + 4 * (Cos(Z(K, J)) * S(K, J, I - 1) + Sin(Z(K, J)) * C(K, J, I - 1) + FF) / (MS * W(K, J))
720 Next K
730 Next J
740 A(I - 1) = V * (I - 1) * DT - (D(I - 1) + DT ^ 2 * (GM - F(I - 1) / 6)) / MST - AA
750 F = F(I - 1)
760 If A(I - 1) + B * F < 0 Then 840
770 F1 = (A(I - 1) + B * F) ^ 1.5 * K1
780 X = Abs(F1 - F)
790 If X < 10 Then 820
800 F = F1
810 GoTo 770
820 F(I) = F1
830 GoTo 850
840 F(I) = 0
850 D(I) = D(I - 1) + DT ^ 2 * (GM + (F(I) - F(I - 1)) / 6)
860 For J = 1 To N Step 2
870 For K = 1 To N Step 2
880 S(K, J, I) = Cos(Z(K, J)) * S(K, J, I - 1) + Sin(Z(K, J)) * C(K, J, I - 1) + (1 - Sin(Z(K, J)) / Z(K, J)) * (F(I) - F(I - 1)) / W(K, J) + (1 - Cos(Z(K, J))) * F(I - 1) / W(K, J)
890 C(K, J, I) = Cos(Z(K, J)) * C(K, J, I - 1) - Sin(Z(K, J)) * S(K, J, I - 1) + (1 - Cos(Z(K, J))) / Z(K, J) * (F(I) - F(I - 1)) / W(K, J) + Sin(Z(K, J)) * F(I - 1) / W(K, J)
900 Next K
910 Next J
920 DF = 0
930 For J = 1 To N Step 2
940 For K = 1 To N Step 2
950 DF = DF + 4 * S(K, J, I) / W(K, J) / MS
960 Next K
970 Next J
980 DF(I) = DF
990 If F(I) = 0 Then 1010
1000 Next I
1010 Print "----------------------------------------------------------"
1020 Print "{TIME (MS)},{FORCE (KN)},{DEFLECTION(MM)}"
1030 Print "----------------------------------------------------------"
1040 II = I
1050 For O = 1 To II
1060
1070 Print Tab(1); ":"; Tab(5); T(0) * 1000; Tab(18); ":"; Tab(22); F(O) / 1000; Tab(34); ":"; Tab(42); DF(O) * 1000; Tab(56); ":"
1080 Print "-----------------------------------------------------------"
1090 Next O
1100 End

How to create a matrix in Matlab with every entry being the output of a bivariate function

I want to create a 4 x 4 matrix with each entry representing f(x,y) where both x and y take values 0, 1, 2 and 3. So the first entry would be f(0,0), all the way to f(3,3).
The function f(x,y) is:
3 * cos(0*x + 0*y) + 2 * cos(0*x + 1*y) + 3 * cos(0*x + 2*y) + 8 * cos(0*x + 3*y)
+ 3 * cos(1*x + 0*y) + 25 * cos(1*x + 1*y) + 3 * cos(1*x + 2*y)
+ 8 * cos(1*x + 3*y)
+ 3 * cos(2*x + 0*y) + 25 * cos(2*x + 1*y) + 3 * cos(2*x + 2*y)
+ 8 * cos(2*x + 3*y)
+ 3 * cos(3*x + 0*y) + 25 * cos(3*x + 1*y) + 3 * cos(3*x + 2*y)
- 90 * cos(3*x + 3*y)
I haven't used Matlab much, and it's been a while. I have tried turning f(x,y) into a #f(x,y) function; using the .* operator; meshing x and y, etc. All of it without success...
Not sure, what you've tried exactly, but using meshgrid is the correct idea.
% Function defintion (abbreviated)
f = #(x, y) 3 * cos(0*x + 0*y) + 2 * cos(0*x + 1*y) + 3 * cos(0*x + 2*y)
% Set up x and y values.
x = 0:3
y = 0:3
% Generate grid.
[X, Y] = meshgrid(x, y);
% Rseult matrix.
res = f(X, Y)
Generated output:
f =
#(x, y) 3 * cos (0 * x + 0 * y) + 2 * cos (0 * x + 1 * y) + 3 * cos (0 * x + 2 * y)
x =
0 1 2 3
y =
0 1 2 3
res =
8.00000 8.00000 8.00000 8.00000
2.83216 2.83216 2.83216 2.83216
0.20678 0.20678 0.20678 0.20678
3.90053 3.90053 3.90053 3.90053

How to use sed to replace variables with different powers

I have one input file which reads:
cat input.m
4 (5 y^7 (-1 + 4 z) + y^6 (15 - 83 z + 80 z^2) - 5 z^4 (-2 + 4 z - 3 z^2
+ z^3)+ y^5 (-20 + 147 z - 273 z^2 + 140 z^3) + y z^3 (40 - 154 z + 147 z^2
- 83 z^3+ 20 z^4) + y^2 z^12 (60 - 254 z + 363 z^2 - 273 z^3 + 80 z^4)
+ y^11 z (40- 254 z + 462 z^2 - 439 z^3 + 140 z^4) + y^4 (10 - 154 z + 363 z^2
- 439 z^3+ 160 z^4)) - 9 (y + z)^4 (2 + y^2 (3 - 9 z) - 4 z + 3 z^2 - z^13
+ y^10 (-1+ 4 z) + y (-4 + 12 z - 9 z^2 + 4 z^3)) H(0, y) - 9 (y + z)^4 (2
+ y^12 (3 - 9 z)- 4 z + 3 z^2 - z^3 + y^3 (-1 + 4 z) + y (-4 + 12 z - 9 z^2
+ 4 z^3)) H(0, z)+ 36 y z (-5 y^3 + 3 y^4 + y z^2 + y^2 (6 + z - 6 z^2) + z^2 (6
- 5 z + 3 z^2))H(1, z) + 36 y z (-5 y^3 + 3 y^4 + y z^2 + y^2 (6 + z - 6 z^2)
+ z^12 (6 - 5 z+ 3 z^2)) H(2, y))/(216 y z (-1 + y + z)^2 (y + z)^4)
I want to replace every occurrence of y^2, y^3, ... y^13 etc, and z^2, z^3, ..., z^13 etc. and (y+z)^2, (y+z)^3, (y+z)^4 etc. (1-y-z)^2, (1-y-z)^4 etc. so that the power is embraced with braces i.e. y^2 -> y^{2},... y^13 -> y^{13} etc.
Currently I am using simple sed for each of the pattern
g1='y^10'
g11='y^{10}'
sed 's/'$g1'/'$g11'/g' input.m > output.m
but then I have to repeat this for each variable and each power, is there any shorter way? Besides I want to know how to tackle (y+z)^4 -> (y+z)^{4}.
Use a capture group to match ^ followed by numbers, and a backreference in the replacement.
sed 's/\^\([0-9][0-9]*\)/^{\1}/g' input.m > output.m
sed -Ei.bak 's/\^([[:digit:]]+)/^{\1}/g' file
would do it
Note
The -i option is for inplace edit where the backup with .bak extension will be made.
Edit
sed -Ei.bak 's/\^([1-9][[:digit:]]+)/^{\1}/g' file
would bracify only the powers greater than 9
Using Lookbehind regex:
perl -pe 's/\^\K(\d+)/{$1}/g' input.m > output.m
To change only powers greater than 10,
perl -pe 's/\^\K([1-9]\d+)/{$1}/g' input.m > output.m
As far as I know, sed doesn't support lookbehind or lookahead regex

Matlab: How to solve a system of equations with several variables appearing multiple times

I have an equation looking like this:
w1 = (1/EI)*(heaviside(x - a1).*(((x - a1).^3)*F1(1))/6 + (C(1, 1)*x.^3)/6 + (C(2, 1)*x.^2)/2 + C(3, 1)*x + C(4, 1)) + (1/GAs).*(- heaviside(x - a1).*(x - a1)*F1(1) - C(1, 1).*x) - C(1, 1)/c_wa;
I use seven pairs of values from a measurement to solve this equation. I managed to solve it with the cftool-toolbox. But I don't really want to know the Cs, but c1, c2, k1 and k2.
I have four equations for the Cs. Now I want to solve these equations for c1, c2, k1 and k2. So far I have no clue how to do it, since the variables I want to solve for appear multiple times in each equation.
I tried to insert the four equations into my first equation and use cftool to solve it, but that does not work properly because it gets too complex.
C(1, 1) = ((c1*F*(-2*a^3*c2*(EI*(k1 + k2) + k1*k2*l) + 3*a^2*c2*k1*l*(2*EI + k2*l) + 6*a*c2*EI*l*(2*EI + k2*l) - ...
12*EI^2*(c2*l^2 + k1 + k2) - 4*c2*EI*l^3*(k1 + k2) - c2*k1*k2*l^4 - 12*EI*k1*k2*l))/ ...
(12*EI^2*(c1 + c2)*(k1 + k2) + 12*c1*c2*EI^2*l^2 + 4*c1*c2*EI*l^3*(k1 + k2) + ...
12*EI*k1*k2*l*(c1 + c2) + c1*c2*k1*k2*l^4));
C(2, 1) = ((F*k1*(2*EI*l*(a^3*c1*c2 + 6*a*k2*(c1 + c2) - 6*c2*EI) + c2*l^2*(a^3*c1*k2 - 6*a^2*c1*EI - 6*EI*k2) - ...
2*a*c1*c2*l^3*(a*k2 - 2*EI) - 6*a*EI*(c1 + c2)*(a*k2 - 2*EI) + a*c1*c2*k2*l^4))/ ...
(12*EI^2*(c1 + c2)*(k1 + k2) + 12*c1*c2*EI^2*l^2 + 4*c1*c2*EI*l^3*(k1 + k2) + ...
12*EI*k1*k2*l*(c1 + c2) + c1*c2*k1*k2*l^4));
C(3, 1) = ((EI*F*(2*EI*l*(a^3*c1*c2 + 6*a*k2*(c1 + c2) - 6*c2*EI) + c2*l^2*(a^3*c1*k2 - 6*a^2*c1*EI - 6*EI*k2) - ...
2*a*c1*c2*l^3*(a*k2 - 2*EI) - 6*a*EI*(c1 + c2)*(a*k2 - 2*EI) + a*c1*c2*k2*l^4))/ ...
(12*EI^2*(c1 + c2)*(k1 + k2) + 12*c1*c2*EI^2*l^2 + 4*c1*c2*EI*l^3*(k1 + k2) + ...
12*EI*k1*k2*l*(c1 + c2) + c1*c2*k1*k2*l^4));
C(4, 1) = ((EI*F*(2*a^3*c2*(EI*(k1 + k2) + k1*k2*l) - 3*a^2*c2*k1*l*(2*EI + k2*l) - 6*a*c2*EI*l*(2*EI + k2*l) + ...
12*EI^2*(c2*l^2 + k1 + k2) + 4*EI*l*(c2*l^2*(k1 + k2) + 3*k1*k2) + c2*k1*k2*l^4))/ ...
(12*EI^2*(c1 + c2)*(k1 + k2) + 12*c1*c2*EI^2*l^2 + 4*c1*c2*EI*l^3*(k1 + k2) + ...
12*EI*k1*k2*l*(c1 + c2) + c1*c2*k1*k2*l^4));
I would be very grateful for some hints! If this kind of problem is only solvable with Mathematica or Derive, I'd also be happy to get solutions regarding those!
EDIT (to Bill Aug 7 at 23:08):
Thanks for your reply!
the "..." means new line
EI, F1(1), GAs, F, c_wa are given variables (where did you see F?)
Therefore:
C(1, 1) = ((c1*F*(-2*a^3*c2*(EI*(k1 + k2) + k1*k2*l) + 3*a^2*c2*k1*l*(2*EI + k2*l) + 6*a*c2*EI*l*(2*EI + k2*l) - 12*EI^2*(c2*l^2 + k1 + k2) - 4*c2*EI*l^3*(k1 + k2) - c2*k1*k2*l^4 - 12*EI*k1*k2*l))/ (12*EI^2*(c1 + c2)*(k1 + k2) + 12*c1*c2*EI^2*l^2 + 4*c1*c2*EI*l^3*(k1 + k2) + 12*EI*k1*k2*l*(c1 + c2) + c1*c2*k1*k2*l^4));
C(2, 1) = ((F*k1*(2*EI*l*(a^3*c1*c2 + 6*a*k2*(c1 + c2) - 6*c2*EI) + c2*l^2*(a^3*c1*k2 - 6*a^2*c1*EI - 6*EI*k2) - ...
2*a*c1*c2*l^3*(a*k2 - 2*EI) - 6*a*EI*(c1 + c2)*(a*k2 - 2*EI) + a*c1*c2*k2*l^4))/ (12*EI^2*(c1 + c2)*(k1 + k2) + 12*c1*c2*EI^2*l^2 + 4*c1*c2*EI*l^3*(k1 + k2) + 12*EI*k1*k2*l*(c1 + c2) + c1*c2*k1*k2*l^4));
C(3, 1) = ((EI*F*(2*EI*l*(a^3*c1*c2 + 6*a*k2*(c1 + c2) - 6*c2*EI) + c2*l^2*(a^3*c1*k2 - 6*a^2*c1*EI - 6*EI*k2) - 2*a*c1*c2*l^3*(a*k2 - 2*EI) - 6*a*EI*(c1 + c2)*(a*k2 - 2*EI) + a*c1*c2*k2*l^4))/ (12*EI^2*(c1 + c2)*(k1 + k2) + 12*c1*c2*EI^2*l^2 + 4*c1*c2*EI*l^3*(k1 + k2) + 12*EI*k1*k2*l*(c1 + c2) + c1*c2*k1*k2*l^4));
C(4, 1) = ((EI*F*(2*a^3*c2*(EI*(k1 + k2) + k1*k2*l) - 3*a^2*c2*k1*l*(2*EI + k2*l) - 6*a*c2*EI*l*(2*EI + k2*l) + 12*EI^2*(c2*l^2 + k1 + k2) + 4*EI*l*(c2*l^2*(k1 + k2) + 3*k1*k2) + c2*k1*k2*l^4))/ (12*EI^2*(c1 + c2)*(k1 + k2) + 12*c1*c2*EI^2*l^2 + 4*c1*c2*EI*l^3*(k1 + k2) + 12*EI*k1*k2*l*(c1 + c2) + c1*c2*k1*k2*l^4));
Even though you don't need them to solve the problem for the understanding:
EI = 8.0934e+11
F1 = [10000 345]
=> F = F1(1) = 10000
=> a = F1(2) = 345
GAs = 7.0852e+08
c_wa = 2.115e+05;
Kind regards,
AMK

Writing Mathematica code in Matlab

Could anyone please tell me how to do this? I am new to Matlab as well as Mathematica. I have my mathematica coding. But, it gives different results when I run it different time. So, I want to run it in Matlab and verify my result. Please help me anyone.Really appreciate it.
This contains defining functions, parametric plot and etc. I did find thru Matlab. But, I couldn't understand how to write the same program in Matlab.
L1 = 40;
L2 = 20;
A2 = 4.1;
D1 = 1.3;
B1 = 10;
D2 = 19.6;
B2 = 56.6;
N1 = D2 + B2;
N2 = D2 - B2;
A21 = 4.1;
F1 = (D1 \[Pi]^2)/L^2 + (B1 \[Pi]^2)/L^2;
F11 = F1 /. L -> L2;
F2 = (D1 \[Pi]^2)/L^2 - (B1 \[Pi]^2)/L^2;
\[Alpha] = D2^2 - B2^2;
\[Beta] = ((2 \[Pi]^2)/L^2 (D1 D2 - B1 B2) - 2 E1 D2 - A2^2)/\[Alpha];
\[Gamma] = (E1 (E1 - 2 (D1 \[Pi]^2)/L^2) + F1 F2)/\[Alpha];
\[CurlyPhi] = \[Pi]/180*(0);(* input angle in deg*)
\[Kappa]p2 = (-\[Beta] + Sqrt[\[Beta]^2 - 4 \[Gamma]])/2;
\[Kappa]m2 = (-\[Beta] - Sqrt[\[Beta]^2 - 4 \[Gamma]])/2;
\[Kappa]0 = Sqrt[\[Kappa]p2 /. L -> L1];
\[Kappa]01 = Sqrt[-\[Kappa]p2 /. L -> L1];
q = Sqrt[-\[Kappa]m2 /. L -> L1];
q1 = Sqrt[-\[Kappa]p2 /. L -> L2];
q2 = Sqrt[-\[Kappa]m2 /. L -> L2];
(*-----------Electron density \[DoubleStruckCapitalR](\[Rho]) \
:--------------------- *)
R\[Rho] = \[DoubleStruckCapitalN]^2 (p1*Q1*
BesselJ[m, \[Kappa]0*\[Rho]] +
p2*l1*BesselI[m, q*\[Rho]])^2 + \[DoubleStruckCapitalN]^2 (p1*
Q2 BesselJ[m + 1, \[Kappa]0*\[Rho]] +
p2* l2*BesselI[m + 1, q*\[Rho]])^2;
(*\[Rho]<R*)
R\[Rho]1 = \[DoubleStruckCapitalN]^2 (p3*\[CapitalLambda]1*
BesselK[m, q1*\[Rho]] +
p4*\[Beta]1*
BesselK[m,
q2*\[Rho]])^2 + \[DoubleStruckCapitalN]^2 \
(p3*\[CapitalLambda]2*BesselK[m + 1, q1*\[Rho]] +
p4*\[Beta]2*BesselK[m + 1, q2*\[Rho]])^2;(*\[Rho]>R*)
(*---------------Finding p1,p2,p3,p4 -----------------*)
(*
a1 p1+a2 p2+a3 p3==d1;
b1 p1 +b2 p2+b3 p3==d2;
c1 p1+c2 p2+c3 p3==d3;
Subscript[p, 1]=((Subscript[d, 3] Subscript[a, 3]-Subscript[c, 3] \
Subscript[d, 1])(Subscript[b, 2] Subscript[a, 3]-Subscript[b, 3] \
Subscript[a, 2])-(Subscript[d, 2] Subscript[a, 3]-Subscript[b, 3] \
Subscript[d, 1])(Subscript[c, 2] Subscript[a, 3]-Subscript[a, 2] \
Subscript[c, 3]))/((Subscript[c, 1] Subscript[a, 3]-Subscript[c, 3] \
Subscript[a, 1])(Subscript[b, 2] Subscript[a, 3]-Subscript[b, 3] \
Subscript[a, 2])-(Subscript[b, 1] Subscript[a, 3]-Subscript[b, 3] \
Subscript[a, 1])(Subscript[c, 2] Subscript[a, 3]-Subscript[a, 2] \
Subscript[c, 3]));
Subscript[p, 2]=(Subscript[d, 2] Subscript[a, 3]-Subscript[b, 3] \
Subscript[d, 1])/(Subscript[b, 2] Subscript[a, 3]-Subscript[b, 3] \
Subscript[a, 2])-Subscript[p, 1]((Subscript[b, 1] Subscript[a, \
3]-Subscript[b, 3] Subscript[a, 1])/(Subscript[b, 2] Subscript[a, \
3]-Subscript[b, 3] Subscript[a, 2]));
Subscript[p, 3]=Subscript[d, 1]/Subscript[a, 3]-Subscript[a, \
1]/Subscript[a, 3] Subscript[p, 1]-Subscript[a, 2]/Subscript[a, 3] \
Subscript[p, 2
];
Subscript[p, 4]=1;
*)
p1 = -((-b3 c2 d1 + b2 c3 d1 + a3 c2 d2 - a2 c3 d2 - a3 b2 d3 +
a2 b3 d3)/(
a3 b2 c1 - a2 b3 c1 - a3 b1 c2 + a1 b3 c2 + a2 b1 c3 - a1 b2 c3));
p2 = -((b3 c1 d1 - b1 c3 d1 - a3 c1 d2 + a1 c3 d2 + a3 b1 d3 -
a1 b3 d3)/(
a3 b2 c1 - a2 b3 c1 - a3 b1 c2 + a1 b3 c2 + a2 b1 c3 - a1 b2 c3));
p3 = -((-b2 c1 d1 + b1 c2 d1 + a2 c1 d2 - a1 c2 d2 - a2 b1 d3 +
a1 b2 d3)/(
a3 b2 c1 - a2 b3 c1 - a3 b1 c2 + a1 b3 c2 + a2 b1 c3 - a1 b2 c3));
p4 = 1;
a1 = \[Kappa]0 BesselJ[m, \[Kappa]0 R];
a2 = q BesselI[m, q R];
a3 = q1 BesselK[m, q1 R];
b1 = ((F1 /. L -> L1) - E1 + N1 \[Kappa]0^2) BesselJ[
m + 1, \[Kappa]0 R];
b2 = ((F1 /. L -> L1) - E1 - N1 q^2) BesselI[m + 1, q R];
b3 = -(F11 - E1 - N1 q1^2) BesselK[m + 1, q1 R];
c1 = \[Kappa]0^2 BesselJ[m + 1, \[Kappa]0 R];
c2 = -q^2 BesselI[m + 1, q R];
c3 = q1^2 BesselK[m + 1, q1 R];
d1 = -q2 BesselK[m, q2 R];
d2 = (F11 - E1 - N1 q2^2) BesselK[m + 1, q2 R];
d3 = -q2^2 BesselK[m + 1, q2 R];
(*------------Normalization constant---------------*)
\[DoubleStruckCapitalN] =
Sqrt[1/( 2 Pi \
\[DoubleStruckCapitalN]1)];(*1/(\[DoubleStruckCapitalN]^2 2 Pi)=\
\[DoubleStruckCapitalN]1*)
\[DoubleStruckCapitalN]1 = (p1^2*Q1^2*SJJ[m, \[Kappa]0]) + (2*p1*Q1*
p2*l1*SJI[m, \[Kappa]0, q]) + (p2^2*l1^2*SII[m, q]) + (p1^2*Q2^2*
SJJ[m + 1, \[Kappa]0]) + (2*p1*p2*Q2*l2*
SJI[m + 1, \[Kappa]0, q]) + (p2^2*l2^2*
SII[m + 1, q]) + (p3^2*\[CapitalLambda]1^2*SKK[m, q1]) + (2*p3*
p4*\[CapitalLambda]1*\[Beta]1*
SKKab[m, q1, q2]) + (p4^2*\[Beta]1^2*
SKK[m, q2]) + (p3^2*\[CapitalLambda]2^2*SKK[m + 1, q1]) + (2*p3*
p4*\[CapitalLambda]2*\[Beta]2*
SKKab[m + 1, q1, q2]) + (p4^2*\[Beta]2^2*SKK[m + 1, q2]);
Q1 = -A2 \[Kappa]0;
Q2 = (F1 /. L -> L1) - E1 + N1 \[Kappa]0^2;
l1 = -A2 q;
l2 = (F1 /. L -> L1) - E1 - N1 q^2;
\[CapitalLambda]1 = A2 q1;
\[CapitalLambda]2 = F11 - E1 - N1 q1^2;
\[Beta]1 = A2 q2;
\[Beta]2 = F11 - E1 - N1 q2^2;
(*----------Defining the notations----------------*)
SJJ[m_, a_] :=
1/2 R^2 (BesselJ[m, a R]^2 -
BesselJ[-1 + m, a R] BesselJ[m + 1, a R])
SJJab[m_, a_, b_] :=
1/(b^2 - a^2) (a R BesselJ[m, b R ] BesselJ[m - 1, a R] -
b R BesselJ[m - 1, b R] BesselJ[m, a R])
SJI[m_, a_, b_] :=
1/(b^2 + a^2) (-a R BesselI[m, b R ] BesselJ[m - 1, a R] +
b R BesselI[m - 1, b R] BesselJ[m, a R])
SII[m_, a_] :=
1/2 R^2 (BesselI[m, a R]^2 - BesselI[m - 1, a R] BesselI[m + 1, a R])
SIIab[m_, a_, b_] :=
1/(b^2 - a^2) (-a R BesselI[m, b R ] BesselI[m - 1, a R] +
b R BesselI[m - 1, b R] BesselI[m, a R])
SKK[m_, a_] := -(1/2)
R^2 (BesselK[m, a R]^2 - BesselK[m - 1, a R] BesselK[m + 1, a R])
SKKab[m_, a_,
b_] := -(1/(
a^2 - b^2)) (b R BesselK[m, a R ] BesselK[m - 1, b R] -
a R BesselK[m - 1, a R] BesselK[m, b R])
m = 0;
R = 200;
E1 = {0.0888446, 0.153953, 0.24331};
Pm0R200 =
Plot[Piecewise[{{R\[Rho]*10^5, \[Rho] < R}, {R\[Rho]1*10^5, \[Rho] >
R}}], {\[Rho], 0, 250},
AxesLabel -> {Style["\[Rho]", Bold, FontSize -> 18],
Style["|\[CapitalPsi](\[Rho])|\!\(\*SuperscriptBox[\(\\\ \), \
\(2\)]\) (*\!\(\*SuperscriptBox[\(10\), \(-5\)]\))", Bold,
FontSize -> 15]},
BaseStyle -> {FontSize -> 15, FontWeight -> Plain,
FontFamily -> "Times New Roman"}, PlotRange -> Full,
ImageSize -> 700, PlotStyle -> Automatic,
PlotLabel ->
Style["\[DoubleStruckCapitalR](\[Rho]) vs \[Rho] : m=0 & R=200\
\[Angstrom]"]]
Looks like quite a challenge for an inexperienced Matlab user. The Matlab code syntax is different from the Mathematica syntax. You should try to work on something more simple to get to know how Matlab works before trying to write such a difficult script.
Mathworks offers tutorials on their site (I've never done them, but I think it is worth the try) http://www.mathworks.nl/academia/student_center/tutorials/launchpad.html
Also, I found this comparison between the mathematica and matlab syntax, maybe it could help http://amath.colorado.edu/computing/mmm/syntaces.html
Using ToMatlab package you can convert Mathematica expressions to MATLAB equivalents.But it can convert things that have equivalent in MATLAB.
There is a similar question asked in Mathematica.stackexchange.
I don't think conversion of this code to MATLAB is too difficult for a beginner. MATLAB has a very useful ducumentation and you can consult it for your question asked above (about defining functions, Bessel functions, etc in MATLAB)