How to write this thetta fuction in Matlab? I have an example code in Python
Ältere Kommentare anzeigen
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 Kommentare
Askic V
am 26 Jan. 2023
Can you please show us your current attempt?
Beket
am 26 Jan. 2023
Askic V
am 26 Jan. 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
am 26 Jan. 2023
Dyuman Joshi
am 26 Jan. 2023
Bearbeitet: Dyuman Joshi
am 26 Jan. 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
am 26 Jan. 2023
Dyuman Joshi
am 26 Jan. 2023
Bearbeitet: Dyuman Joshi
am 26 Jan. 2023
What are c_rinf, w, s and z in the definition of betta?
Are they defined before their use in betta?
Beket
am 26 Jan. 2023
Dyuman Joshi
am 26 Jan. 2023
You can attach it here, use the paperclip icon.
Or you can copy paste releveant code.
Beket
am 26 Jan. 2023
Akzeptierte Antwort
Weitere Antworten (1)
Dyuman Joshi
am 26 Jan. 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 Kommentare
Beket
am 26 Jan. 2023
Dyuman Joshi
am 26 Jan. 2023
I already have your original code. Is this one different from that one?
Beket
am 26 Jan. 2023
Dyuman Joshi
am 26 Jan. 2023
Did you make the changes I suggested in my answer and run the code?
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!