Why is my code not working?

1 回表示 (過去 30 日間)
Charlee
Charlee 2024 年 4 月 16 日
回答済み: Hassaan 2024 年 4 月 16 日
f= @(x) average_f(x);
final = 70; % Intiall estimate
final = fsolve(f,final)
final >= 0;
function average = average_f(final)
scores= [55, 76, 85, 50];
average= (scores + final)/5;
end
if average == 65
end

回答 (1 件)

Hassaan
Hassaan 2024 年 4 月 16 日
f = @(final) average_f(final) - 65; % Define a function that should be zero
initial_estimate = 70; % Initial estimate for fsolve
final = fsolve(f, initial_estimate); % Find final that makes f zero
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
disp(final); % Display the final result
59.0000
function average = average_f(final)
scores = [55, 76, 85, 50];
average = (sum(scores) + final) / (length(scores) + 1); % Correct average calculation
end
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

カテゴリ

Help Center および File ExchangeCombustion and Turbomachinery についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by