How to write this thetta fuction in Matlab? I have an example code in Python
显示 更早的评论
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 个评论
Askic V
2023-1-26
Can you please show us your current attempt?
Beket
2023-1-26
Askic V
2023-1-26
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
2023-1-26
Dyuman Joshi
2023-1-26
编辑:Dyuman Joshi
2023-1-26
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
2023-1-26
Dyuman Joshi
2023-1-26
编辑:Dyuman Joshi
2023-1-26
What are c_rinf, w, s and z in the definition of betta?
Are they defined before their use in betta?
Beket
2023-1-26
Dyuman Joshi
2023-1-26
You can attach it here, use the paperclip icon.
Or you can copy paste releveant code.
Beket
2023-1-26
采纳的回答
更多回答(1 个)
Dyuman Joshi
2023-1-26
@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 个评论
Beket
2023-1-26
Dyuman Joshi
2023-1-26
I already have your original code. Is this one different from that one?
Beket
2023-1-26
Dyuman Joshi
2023-1-26
Did you make the changes I suggested in my answer and run the code?
类别
在 帮助中心 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!