Finding radius of sphere and circle
4 ビュー (過去 30 日間)
古いコメントを表示
Hello! So i'm trying to find the values of radius of a sphere and a circle from their formulas of area and volume.I want my_eval_parameter function to have as arguments the area of the circle (E_C) and the volume of the sphere (E_V) and I want my function to be called back with this way:
[rad1, rad2] = my_eval_parameters(E_C,V_S);
This is the code that I've managed to write:
function my_eval_paramereters=calculations(rad1,rad2)
E_C = input('enter value for E_C:...');
rad1 = pi*(rad1*rad1);
rad2 = input('enter value for V_S:... ');
rad2(rad2) = (4/3)*pi*(rad2^3);
[rad1, rad2] = my_eval_parameters(E_C,rad2);
end
0 件のコメント
回答 (3 件)
Ahmed raafat
2022 年 1 月 22 日
change the output name and write my_eval_parameters code
and change your function code into
function [rad1,rad2]=calculations(rad1,rad2)
2 件のコメント
VBBV
2025 年 4 月 12 日
移動済み: VBBV
2025 年 4 月 12 日
@Nick Vasilakis You can change the code structure as follows, since you would need a recursive function
function calculations(rad1, rad2)
E_C = input('enter value for E_C:...');
%rad1 = pi*(rad1*rad1);
E_V = input('enter value for V_S:... ');
%rad2 = (4/3)*pi*(rad2^3);
[rad1, rad2] = my_eval_parameters(E_C,E_V);
calculations(rad1,rad2)
end
function [rad1, rad2] = my_eval_parameters(E_C,E_V)
rad1 = sqrt(E_C/pi)
rad2 = ((3*E_V)/(4*pi))^(1/3)
end
%E_C = input('enter value for E_C:...');rad1 = pi*(rad1*rad1);rad2 = input('enter value for V_S:... ');rad2(rad2) = (4/3)*pi*(rad2^3);[rad1, rad2] = my_eval_parameters(E_C,rad2);end
1 件のコメント
VBBV
2025 年 4 月 12 日
hopefully you know a way to stop the recursion. In most cases you need a break statement
inside calculations function.
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!