How to write this thetta fuction in Matlab? I have an example code in Python
Mostrar comentarios más antiguos
How to write this thetta fuction in Matlab?

Someone wrote it in Python like this:
def thetta(r):
thettar = np.zeros(r.size)
h = (r_2 - r_1) / N
for i in range(r.size):
for j in range(i):
thettar[i] += h * 0.5 * (1 / (r[j] * math.tan(betta(r[j]))) + 1 / (r[j+1] * math.tan(betta(r[j+1]))))
return thettar
10 comentarios
Askic V
el 26 de En. de 2023
Can you please show us your current attempt?
Beket
el 26 de En. de 2023
Askic V
el 26 de En. de 2023
How is betta defined? You should be able to execute the same code in Python and Matlab and compare results.
Matlab has some very good built in functions for integration. For numerical integration I use cumtrapz, but I guess your task is to rewrite the Python implementation to Matlab.
Beket
el 26 de En. de 2023
Dyuman Joshi
el 26 de En. de 2023
Editada: Dyuman Joshi
el 26 de En. de 2023
Are you getting an error? If so, please mention the full error.
And/Or are you not getting the output you want? In that case, attach or provide the full code and data for r (a sample data would work as well) and the corresponding required output.
Beket
el 26 de En. de 2023
Dyuman Joshi
el 26 de En. de 2023
Editada: Dyuman Joshi
el 26 de En. de 2023
What are c_rinf, w, s and z in the definition of betta?
Are they defined before their use in betta?
Beket
el 26 de En. de 2023
Dyuman Joshi
el 26 de En. de 2023
You can attach it here, use the paperclip icon.
Or you can copy paste releveant code.
Beket
el 26 de En. de 2023
Respuesta aceptada
Más respuestas (1)
Dyuman Joshi
el 26 de En. de 2023
@Beket, your code needs some changes
94th and 95th line of your code, you used b in c_rinf before defining it.
c_rinf = @(r) Q_rk ./ (2 .* pi .* r .* b(r));
b = @(r) b_1 - (b_1 - b_2) ./ (r_2 - r_1) .* (r - r_1);
Similarly, in lines 110th and 111th, you used r in thettar before defining it.
thettar = zeros(size(r));
r = linspace(r_1, r_2, N);
Correct the order and the error will be rectified.
Also, while defining a function handle, it's better to use element-wise operators .*, ./ and .^ , you can see that change above in c_rinf and b.
Your code still has some errors, mostly syntax errors (check line 121 and 150).
Additionally, what is the purpose of these lines?
bettar = betta(r);
thettar = thettar(r);
4 comentarios
Beket
el 26 de En. de 2023
Dyuman Joshi
el 26 de En. de 2023
I already have your original code. Is this one different from that one?
Beket
el 26 de En. de 2023
Dyuman Joshi
el 26 de En. de 2023
Did you make the changes I suggested in my answer and run the code?
Categorías
Más información sobre Call Python from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!