필터 지우기
필터 지우기

function calling problem in my main

조회 수: 3 (최근 30일)
passioncoding
passioncoding 2019년 4월 9일
댓글: passioncoding 2019년 4월 9일
function [O]=fitness(x1,y1,x2,y2,start,goal)
dis=distance(start,goal);
theta=pathsmoothness (x1,x2,y1,y2,goal);
z=dis+theta;
O=1/(z+0.001);
end
function theta= pathsmoothness (x1,x2,y1,y2,goal)
theta1 =atan((y2-y1)/(x2-x1));
theta2= atan(((goal(2))-(y1))/(goal(1)-(x2)));
theta= theta1-theta2;
end
function [dis] = distance(start,goal)
%This function calculates the distance between any two cartesian coordinates.
delta_x=goal(1)-start(1);
delta_y=goal(2)-start(2);
% Calculate the distance to the goal
dis=sqrt(delta_x^2+delta_y^2);
%dis=sqrt((x1-x2).^2 + (y1-y2).^2);
end
Consider Start=[1,1] and goal [10,10]
When I try to call fitness function at the following line in my code. it says to many input arguments.
[particle(i).Cost, particle(i).Sol]=fitness(particle(i).Position);
I dont know how to resolve it.
  댓글 수: 2
KSSV
KSSV 2019년 4월 9일
Your function accepts x1,y1,x2,y2,start,goal........what does particle(i).Position output?
passioncoding
passioncoding 2019년 4월 9일
function sol1=createsolution(model)
n=model.n;
Xmin=model.Xmin;
Xmax=model.Xmax;
Ymin=model.Ymin;
Ymax=model.Ymax;
sol1.x=unifrnd(Xmin,Xmax,1,n);
sol1.y=unifrnd(Ymin,Ymax,1,n);
end
THis is particle psoition.
particle(i).Position=createsolution(model)
model is another function in which parameters of robot are given they are as follows:
function model=Makingmodel()
%source
xMR=1;
yMR=1;
%goal
xG=10;
yG=10;
SP=[xMR,yMR];
GP=[xG,yG];
%obstacle=[];
xobs=[3 3];
yobs=[3 3;5 7];
robs=[3 1;4 7;7 9;1 8;9 3;5 6;7 7];
n=3;
Xmin=-11;
Xmax= 11;
Ymin=-11;
Ymax= 11;
model.xMR=xMR;
model.yMR=yMR;
model.xG=xG;
model.yG=yG;
model.xobs=xobs;
model.yobs=yobs;
model.robs=robs;
model.n=n;
model.Xmin=Xmin;
model.Xmax=Xmax;
model.Ymin=Ymin;
model.Ymax=Ymax;
%p.XYMAX=11;
%map=zeros(p.XYMAX,p.XYMAX)+inf;
%map(p.GP(1),p.GP(2))=0;
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Analog Input and Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by