Home > source > convertToSdp.m

convertToSdp

PURPOSE ^

Converts Syms variables into sdpvar().

SYNOPSIS ^

function [ alfa ] = convertToSdp( alfa )

DESCRIPTION ^

Converts Syms variables into sdpvar().

This function looks for Syms variables in alfa string vector and replace
them with sdpvar() variables.

Prorotype: [alfa] = convertToSdp(alfa).

Input:     alfa - is a equation string vector with Syms variable.

Output:    alfa -same alfa's syntax but with sdpvar() variable istead of Syms.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %Converts Syms variables into sdpvar().
0002 %
0003 %This function looks for Syms variables in alfa string vector and replace
0004 %them with sdpvar() variables.
0005 %
0006 %Prorotype: [alfa] = convertToSdp(alfa).
0007 %
0008 %Input:     alfa - is a equation string vector with Syms variable.
0009 %
0010 %Output:    alfa -same alfa's syntax but with sdpvar() variable istead of Syms.
0011 
0012 %Claudio Fantacci & Alessandro Martini.
0013 
0014 function [ alfa ] = convertToSdp( alfa )
0015 
0016 sdpIndex = 1;
0017 
0018 for i = 1:length(alfa)
0019     target = char(alfa(i));
0020     if alfa(i) ~= 0 && isempty(strfind(target,'+')) && isempty(strfind(char(alfa(i)),'-')) && isempty(strfind(char(alfa(i)),'*'))
0021         names{sdpIndex} = target;
0022         sdpalfa{sdpIndex} = sdpvar(1);
0023         sdpIndex = sdpIndex + 1;
0024     end
0025 end
0026 
0027 for i = 1:length(alfa)
0028     if ~isempty(strfind(char(alfa(i)),'+')) || ~isempty(strfind(char(alfa(i)),'-')) || ~isempty(strfind(char(alfa(i)),'*'))
0029         chr = strrep(char(alfa(i)),'+',' +');
0030         chr = strrep(chr,'-',' -');
0031         chr = strrep(chr,'*','* ');
0032         pieces = strsplit(' ',chr);
0033         for k=1:length(names)
0034             nameToCheck = names{k};
0035             found = false;
0036             index = 1;
0037             while ~found && index <= length(pieces)
0038                 pieceToControl = char(pieces{index});
0039                 if ~isempty(strfind(pieceToControl,nameToCheck))
0040                     pieces{index} = sdpalfa{k};
0041                     found = true;
0042                 else
0043                     index = index + 1;
0044                 end
0045             end
0046         end
0047         result = '';
0048         for k = 1:length(pieces)
0049             if isempty(strfind(class(pieces{k}),'sdpvar'))
0050                 result = strcat(result,char(pieces{k}));
0051             else
0052                 string = cell2str(names{k});
0053                 result = strcat(result,string);
0054             end
0055         end
0056         command = strcat('sdpalfa{',num2str(i),'}=',result,';');
0057         eval(command);
0058     end
0059     
0060 end
0061 
0062 return;

Generated on Thu 24-Sep-2009 17:17:32 by m2html © 2005