for loop with fminsearch

5 次查看(过去 30 天)
%I couldnt make array values of Theta_2
u=deg2rad(13)
eqn1= @(t1, u) u+atan(sin(t1)./(1-cos(t1)))-pi/2 % theta1 t1 olarak tanımlanmıştır.
Theta_1_initial= (fminsearch(@(t1)norm(eqn1(t1, u)),u))
Theta_1=linspace(Theta_1_initial,pi/2,100)
for i=1;100
Theta_2(i)=THETA (Theta_1(i),u)
end
function [Theta_2] = THETA (Theta_1,u)
eqn=@(Theta_2,Theta_1,u) cos(Theta_2)+sin(Theta_2).*tan(pi/2-atan(sin(Theta_2)./(cos(Theta_1)+sin(Theta_1).*tan(u)-cos(Theta_2))))-cos(Theta_1)-sin(Theta_1).*tan(u);
Theta_2=fminsearch(@(Theta_2)norm(eqn(Theta_2,Theta_1,u)),Theta_1);
end

采纳的回答

Star Strider
Star Strider 2023-9-30
There is a typographical error:
for i=1;100
↑← HERE
Change that to a colon and it works —
%I couldnt make array values of Theta_2
u=deg2rad(13)
u = 0.2269
eqn1= @(t1, u) u+atan(sin(t1)./(1-cos(t1)))-pi/2 % theta1 t1 olarak tanımlanmıştır.
eqn1 = function_handle with value:
@(t1,u)u+atan(sin(t1)./(1-cos(t1)))-pi/2
Theta_1_initial= (fminsearch(@(t1)norm(eqn1(t1, u)),u));
Theta_1=linspace(Theta_1_initial,pi/2,100);
for i=1:100
Theta_2(i)=THETA (Theta_1(i),u);
end
Theta_2
Theta_2 = 1×100
0.4311 0.4651 0.4764 0.4876 0.4740 0.5102 0.5215 0.5328 0.5440 0.5553 0.5666 0.6068 0.5892 0.6005 0.6117 0.6230 0.6343 0.6456 0.6569 0.6682 0.6455 0.6907 0.7020 0.7133 0.7246 0.6991 0.7471 0.7963 0.7697 0.7419
function [Theta_2] = THETA (Theta_1,u)
eqn=@(Theta_2,Theta_1,u) cos(Theta_2)+sin(Theta_2).*tan(pi/2-atan(sin(Theta_2)./(cos(Theta_1)+sin(Theta_1).*tan(u)-cos(Theta_2))))-cos(Theta_1)-sin(Theta_1).*tan(u);
Theta_2=fminsearch(@(Theta_2)norm(eqn(Theta_2,Theta_1,u)),Theta_1);
end
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by