最近开始做自己的毕业设计,开始记录相关的智能控制学习心得和知识点.
bp算法全称BackPropagation,也就是误差反向传播算法,它的基本思想是梯度下降法,采用梯度搜索技术,通过链式求导法则,最终使得网络输出和期望输出的误差方差最小.BP算法的图如下图所示:
三层网络:输入层,隐藏层和输出层.网络的前向传播和误差反向传播可参考这篇博客:大白话讲解BP算法.这里主要涉及到的是对于sigmod函数的求导.
这里有一个BP算法逼近的示例(《智能控制》第4版 page131),系统的传递函数如下:
clear all
close all
xite = 0.5;%学习速率
alfa = 0.1;%动量因子,动量因子大一点可以减小振荡,加快收敛,太大了会发散
w2=rands(6,1);%隐藏层和输出层的连接(隐藏层6个神经元)
w2_1=w2;w2_2=w2_1;
w1=rands(2,6);%输入层和隐藏层的连接(输入层两个u(k)和y(k))
w1_1=w1;w1_2=w1;
dwl=0*w1;%2x6,初始化为0
x=[0,0]';%输入初始化
u_1 = 0;
y_1 = 0;
I=[0,0,0,0,0,0]';
Iout=[0,0,0,0,0,0]';
FI=[0,0,0,0,0,0]';
ts=0.001;%步长
for k = 1:1:1000
time(k) = k*ts;
u(k) = 0.5*sin(3*2*pi*k*ts);%输入u(k)
y(k)=u_1^3+y_1/(1+y_1^2);%实际输出y(k)
for j =1:1:6
I(j)=x'*w1(:,j);%I是一个三维的数组,输入层乘以权重到隐藏层
Iout(j)=1/(1+exp(-I(j)));%sigmod函数,即f(net)
end
yn(k)=w2'*Iout;%输出
e(k)=y(k)-yn(k)%误差
w2=w2_1+(xite*e(k))*Iout+alfa*(w2_1-w2_2);%隐藏层到输出层的梯度,此处求导不涉及sigmod 函数
for j=1:1:6
FI(j)=exp(-I(j))/(1+exp(-I(j)))^2;%sigmod函数的求导结果
end
for i=1:1:2
for j =1:1:6
dw1(i,j)=e(k)*xite*FI(j)*w2(j)*x(i);%隐藏层到输入层的误差梯度
end
end
w1=w1_1+dw1+alfa*(w1_1-w1_2);%更新输入层到隐藏层权重
yu=0;
for j=1:1:6
yu=yu+w2(j)*w1(1,j)*FI(j);
end
dyu(k)=yu;%Jacobian信息
x(1)=u(k);
x(2)=y(k);
w1_2=w1_1;w1_1=w1;
w2_2=w2_1;w2_1=w2;
u_1=u(k)
y_1=y(k)
end
figure(1);
plot(time,y,'r',time,yn,'b');
xlabel('time(s)');ylabel('y and yn');
figure(2);
plot(time,y-yn,'r')
xlabel('time(s)');ylabel('error');
figure(3);
plot(time,dyu);
xlabel('time(s)');ylabel('dy')
BP算法只要有足够多的隐藏层和隐藏节点,理论上是可以逼近任意的非线性系统的,它属于全局逼近算法,具有较强的泛化能力.但是BP算法待优化参数多,收敛速度慢,难以确定隐藏层和隐藏节点数,很多时候要靠经验试凑.难以适应实时控制的要求.
径向基函数(Radial Basis Function,RBF)神经网络是一种三层网络.其学习过程和BP算法类似,二者的主要区别在于:(1)隐藏层的激活函数不同,BP算法的激活函数是sigmod函数,RBF的激活函数是高斯基函数;(2)BP算法是全局的逼近,每次学习都要进行所有网络连接的权重迭代更新,RBF是一种局部逼近,其输入层到输层是非线性映射,但其隐藏层到输出层是线性映射的.且输入层到隐藏层直接求和,不需要参数迭代.
首先给出高斯径向基函数的表达式:
我们同样是跟踪BP仿真的系统,模型结构如下:
model代码:
Model {
Name "rbfsim"
Version 8.8
SavedCharacterEncoding "UTF-8"
GraphicalInterface {
NumRootInports 0
NumRootOutports 0
ParameterArgumentNames ""
ComputedModelVersion "1.235"
NumModelReferences 0
NumTestPointedSignals 0
NumProvidedFunctions 0
NumRequiredFunctions 0
NumResetEvents 0
HasInitializeEvent 0
HasTerminateEvent 0
IsExportFunctionModel 0
}
LogicAnalyzerGraphicalSettings ""
LogicAnalyzerPlugin "on"
LogicAnalyzerSignalOrdering ""
DiagnosticSuppressor "on"
SuppressorTable "22 serialization::archive 11 0 3 0 0 0 11 0"
ScopeRefreshTime 0.035000
OverrideScopeRefreshTime on
DisableAllScopes off
DataTypeOverride "UseLocalSettings"
DataTypeOverrideAppliesTo "AllNumericTypes"
MinMaxOverflowLogging "UseLocalSettings"
MinMaxOverflowArchiveMode "Overwrite"
FPTRunName "Run 1"
MaxMDLFileLineLength 120
LastSavedArchitecture "glnxa64"
Object {
$PropName "BdWindowsInfo"
$ObjectID 1
$ClassName "Simulink.BDWindowsInfo"
Object {
$PropName "WindowsInfo"
$ObjectID 2
$ClassName "Simulink.WindowInfo"
IsActive [1]
Location [12.0, 45.0, 1946.0, 1189.0]
Object {
$PropName "ModelBrowserInfo"
$ObjectID 3
$ClassName "Simulink.ModelBrowserInfo"
Visible [0]
DockPosition "Left"
Width [50]
Height [50]
Filter [8]
}
Object {
$PropName "ExplorerBarInfo"
$ObjectID 4
$ClassName "Simulink.ExplorerBarInfo"
Visible [1]
}
Object {
$PropName "EditorsInfo"
$ObjectID 5
$ClassName "Simulink.EditorInfo"
IsActive [1]
ViewObjType "SimulinkTopLevel"
LoadSaveID "0"
Extents [1890.0, 1010.0]
ZoomFactor [3.78]
Offset [0.0, 0.0]
}
Object {
$PropName "DockComponentsInfo"
$ObjectID 6
$ClassName "Simulink.DockComponentInfo"
Type "GLUE2:PropertyInspector"
ID "Property Inspector"
Visible [0]
CreateCallback ""
UserData ""
Floating [0]
DockPosition "Right"
Width [640]
Height [480]
}
WindowState "AAAA/wAAAAD9AAAAAgAAAAAAAAC9AAAB+PwCAAAAA/sAAAAWAEQAbwBjAGsAVwBpAGQAZwBlAHQAMwEAAAAxAAAB+AAAA"
"AAAAAAA+wAAABYARABvAGMAawBXAGkAZABnAGUAdAA0AAAAAAD/////AAAAAAAAAAD7AAAAUgBHAEwAVQBFADIAIAB0AHIAZQBlACAAYwBvAG0Ac"
"ABvAG4AZQBuAHQALwBHAEwAVQBFADIAIAB0AHIAZQBlACAAYwBvAG0AcABvAG4AZQBuAHQAAAAAAP////8AAABXAP///wAAAAEAAAAAAAAAAPwCA"
"AAAAfsAAABUAEcATABVAEUAMgA6AFAAcgBvAHAAZQByAHQAeQBJAG4AcwBwAGUAYwB0AG8AcgAvAFAAcgBvAHAAZQByAHQAeQAgAEkAbgBzAHAAZ"
"QBjAHQAbwByAAAAAAD/////AAAAJwD///8AAAeGAAAEKgAAAAEAAAACAAAAAQAAAAL8AAAAAQAAAAIAAAAP/////wAAAAAA/////wAAAAAAAAAA/"
"////wEAAAAA/////wAAAAAAAAAA/////wAAAAAA/////wAAAAAAAAAA/////wAAAAAA/////wAAAAAAAAAA/////wAAAAAA/////wAAAAAAAAAA/"
"////wEAAAB5/////wAAAAAAAAAA/////wEAAADa/////wAAAAAAAAAA/////wAAAAAA/////wAAAAAAAAAA/////wEAAAFT/////wAAAAAAAAAA/"
"////wAAAAAA/////wAAAAAAAAAA/////wAAAAAA/////wAAAAAAAAAA/////wAAAAAA/////wAAAAAAAAAA/////wEAAANY/////wAAAAAAAAAA/"
"////wEAAAOH/////wAAAAAAAAAA/////wAAAAAA/////wAAAAAAAAAA"
}
}
Created "Thu May 08 09:06:03 2003"
Creator "hp"
UpdateHistory "UpdateHistoryNever"
ModifiedByFormat "%"
LastModifiedBy "fc"
ModifiedDateFormat "%"
LastModifiedDate "Thu Aug 02 09:34:57 2018"
RTWModifiedTimeStamp 455043278
ModelVersionFormat "1.%"
ConfigurationManager "none"
SampleTimeColors off
SampleTimeAnnotations off
LibraryLinkDisplay "none"
WideLines off
ShowLineDimensions off
ShowPortDataTypes off
ShowEditTimeErrors on
ShowEditTimeWarnings on
ShowEditTimeAdvisorChecks off
ShowPortUnits off
ShowDesignRanges off
ShowLoopsOnError on
IgnoreBidirectionalLines off
ShowStorageClass off
ShowTestPointIcons on
ShowSignalResolutionIcons on
ShowViewerIcons on
SortedOrder off
VariantCondition off
ExecutionContextIcon off
ShowLinearizationAnnotations on
ShowVisualizeInsertedRTB on
ShowMarkup on
BlockNameDataTip off
BlockParametersDataTip on
BlockDescriptionStringDataTip off
ToolBar on
StatusBar on
BrowserShowLibraryLinks off
FunctionConnectors off
BrowserLookUnderMasks off
SimulationMode "normal"
PauseTimes "5"
NumberOfSteps 1
SnapshotBufferSize 10
SnapshotInterval 10
NumberOfLastSnapshots 0
LinearizationMsg "none"
Profile off
ParamWorkspaceSource "MATLABWorkspace"
AccelSystemTargetFile "accel.tlc"
AccelTemplateMakefile "accel_default_tmf"
AccelMakeCommand "make_rtw"
TryForcingSFcnDF off
Object {
$PropName "DataLoggingOverride"
$ObjectID 7
$ClassName "Simulink.SimulationData.ModelLoggingInfo"
model_ "rbfsim"
Array {
Type "Cell"
Dimension 1
Cell "rbfsim"
PropName "logAsSpecifiedByModels_"
}
Array {
Type "Cell"
Dimension 1
Cell ""
PropName "logAsSpecifiedByModelsSSIDs_"
}
}
ExtModeBatchMode off
ExtModeEnableFloating on
ExtModeTrigType "manual"
ExtModeTrigMode "oneshot"
ExtModeTrigPort "1"
ExtModeTrigElement "any"
ExtModeTrigDuration 1000
ExtModeTrigDurationFloating "auto"
ExtModeTrigHoldOff 0
ExtModeTrigDelay 0
ExtModeTrigDirection "rising"
ExtModeTrigLevel 0
ExtModeArchiveMode "off"
ExtModeAutoIncOneShot off
ExtModeIncDirWhenArm off
ExtModeAddSuffixToVar off
ExtModeWriteAllDataToWs off
ExtModeArmWhenConnect off
ExtModeSkipDownloadWhenConnect off
ExtModeLogAll on
ExtModeAutoUpdateStatusClock on
ShowModelReferenceBlockVersion off
ShowModelReferenceBlockIO off
Array {
Type "Handle"
Dimension 1
Simulink.ConfigSet {
$ObjectID 8
Version "1.16.5"
DisabledProps []
Description ""
Array {
Type "Handle"
Dimension 9
Simulink.SolverCC {
$ObjectID 9
Version "1.16.5"
DisabledProps []
Description ""
StartTime "0.0"
StopTime "30"
AbsTol "auto"
FixedStep "0.001"
InitialStep "auto"
MaxNumMinSteps "-1"
MaxOrder 5
ZcThreshold "auto"
ConsecutiveZCsStepRelTol "10*128*eps"
MaxConsecutiveZCs "1000"
ExtrapolationOrder 4
NumberNewtonIterations 1
MaxStep "auto"
MinStep "auto"
MaxConsecutiveMinStep "1"
RelTol "1e-5"
EnableMultiTasking on
EnableConcurrentExecution off
ConcurrentTasks off
Solver "ode3"
SolverName "ode3"
SolverJacobianMethodControl "auto"
ShapePreserveControl "DisableAll"
ZeroCrossControl "UseLocalSettings"
ZeroCrossAlgorithm "Nonadaptive"
AlgebraicLoopSolver "TrustRegion"
SolverInfoToggleStatus off
IsAutoAppliedInSIP off
SolverResetMethod "Fast"
PositivePriorityOrder off
AutoInsertRateTranBlk off
SampleTimeConstraint "Unconstrained"
InsertRTBMode "Whenever possible"
SampleTimeProperty []
}
Simulink.DataIOCC {
$ObjectID 10
Version "1.16.5"
DisabledProps []
Description ""
Decimation "1"
ExternalInput "[t, u]"
FinalStateName "xFinal"
InitialState "xInitial"
LimitDataPoints off
MaxDataPoints "1000"
LoadExternalInput off
LoadInitialState off
SaveFinalState off
SaveCompleteFinalSimState off
SaveFormat "Array"
SignalLoggingSaveFormat "ModelDataLogs"
SaveOutput on
SaveState off
SignalLogging on
DSMLogging on
InspectSignalLogs off
VisualizeSimOutput on
StreamToWorkspace off
StreamVariableName "streamout"
SaveTime on
ReturnWorkspaceOutputs off
StateSaveName "xout"
TimeSaveName "tout"
OutputSaveName "yout"
SignalLoggingName "sigsOut"
DSMLoggingName "dsmout"
OutputOption "RefineOutputTimes"
OutputTimes "[]"
ReturnWorkspaceOutputsName "out"
Refine "1"
LoggingToFile off
LoggingFileName "out.mat"
LoggingIntervals "[-inf, inf]"
}
Simulink.OptimizationCC {
$ObjectID 11
Version "1.16.5"
Array {
Type "Cell"
Dimension 8
Cell "ZeroExternalMemoryAtStartup"
Cell "ZeroInternalMemoryAtStartup"
Cell "NoFixptDivByZeroProtection"
Cell "OptimizeModelRefInitCode"
Cell "BooleansAsBitfields"
Cell "PassReuseOutputArgsAs"
Cell "PassReuseOutputArgsThreshold"
Cell "UseSpecifiedMinMax"
PropName "DisabledProps"
}
Description ""
BlockReduction on
BooleanDataType off
ConditionallyExecuteInputs on
DefaultParameterBehavior "Tunable"
UseDivisionForNetSlopeComputation "off"
UseFloatMulNetSlope off
DefaultUnderspecifiedDataType "double"
UseSpecifiedMinMax off
InlineInvariantSignals off
OptimizeBlockIOStorage on
BufferReuse on
EnhancedBackFolding off
CachingGlobalReferences off
GlobalBufferReuse on
StrengthReduction off
AdvancedOptControl ""
ExpressionFolding on
BooleansAsBitfields off
BitfieldContainerType "uint_T"
EnableMemcpy on
MemcpyThreshold 64
PassReuseOutputArgsAs "Structure reference"
PassReuseOutputArgsThreshold 12
ExpressionDepthLimit 2147483647
LocalBlockOutputs on
RollThreshold 5
StateBitsets off
DataBitsets off
ActiveStateOutputEnumStorageType "Native Integer"
ZeroExternalMemoryAtStartup on
ZeroInternalMemoryAtStartup on
InitFltsAndDblsToZero on
NoFixptDivByZeroProtection off
EfficientFloat2IntCast off
EfficientMapNaN2IntZero on
LifeSpan "inf"
MaxStackSize "Inherit from target"
BufferReusableBoundary on
SimCompilerOptimization "off"
AccelVerboseBuild off
}
Simulink.DebuggingCC {
$ObjectID 12
Version "1.16.5"
Array {
Type "Cell"
Dimension 1
Cell "UseOnlyExistingSharedCode"
PropName "DisabledProps"
}
Description ""
RTPrefix "error"
ConsistencyChecking "none"
ArrayBoundsChecking "none"
SignalInfNanChecking "none"
SignalRangeChecking "none"
ReadBeforeWriteMsg "UseLocalSettings"
WriteAfterWriteMsg "UseLocalSettings"
WriteAfterReadMsg "UseLocalSettings"
AlgebraicLoopMsg "warning"
ArtificialAlgebraicLoopMsg "warning"
SaveWithDisabledLinksMsg "warning"
SaveWithParameterizedLinksMsg "none"
CheckSSInitialOutputMsg on
UnderspecifiedInitializationDetection "Classic"
MergeDetectMultiDrivingBlocksExec "none"
CheckExecutionContextPreStartOutputMsg off
CheckExecutionContextRuntimeOutputMsg off
SignalResolutionControl "TryResolveAllWithWarning"
BlockPriorityViolationMsg "warning"
MinStepSizeMsg "warning"
TimeAdjustmentMsg "none"
MaxConsecutiveZCsMsg "error"
MaskedZcDiagnostic "warning"
IgnoredZcDiagnostic "warning"
SolverPrmCheckMsg "none"
InheritedTsInSrcMsg "warning"
MultiTaskDSMMsg "warning"
MultiTaskCondExecSysMsg "none"
MultiTaskRateTransMsg "error"
SingleTaskRateTransMsg "none"
TasksWithSamePriorityMsg "warning"
SigSpecEnsureSampleTimeMsg "warning"
CheckMatrixSingularityMsg "none"
IntegerOverflowMsg "warning"
Int32ToFloatConvMsg "warning"
ParameterDowncastMsg "error"
ParameterOverflowMsg "error"
ParameterUnderflowMsg "none"
ParameterPrecisionLossMsg "warning"
ParameterTunabilityLossMsg "warning"
FixptConstUnderflowMsg "none"
FixptConstOverflowMsg "none"
FixptConstPrecisionLossMsg "none"
UnderSpecifiedDataTypeMsg "none"
UnnecessaryDatatypeConvMsg "none"
VectorMatrixConversionMsg "none"
InvalidFcnCallConnMsg "error"
FcnCallInpInsideContextMsg "warning"
SignalLabelMismatchMsg "none"
UnconnectedInputMsg "warning"
UnconnectedOutputMsg "warning"
UnconnectedLineMsg "warning"
UseOnlyExistingSharedCode "error"
SFcnCompatibilityMsg "none"
FrameProcessingCompatibilityMsg "error"
UniqueDataStoreMsg "none"
BusObjectLabelMismatch "warning"
RootOutportRequireBusObject "warning"
AssertControl "UseLocalSettings"
AllowSymbolicDim on
RowMajorDimensionSupport off
ModelReferenceIOMsg "none"
ModelReferenceMultiInstanceNormalModeStructChecksumCheck "error"
ModelReferenceVersionMismatchMessage "none"
ModelReferenceIOMismatchMessage "none"
UnknownTsInhSupMsg "warning"
ModelReferenceDataLoggingMessage "warning"
ModelReferenceSymbolNameMessage "warning"
ModelReferenceExtraNoncontSigs "error"
StateNameClashWarn "warning"
SimStateInterfaceChecksumMismatchMsg "warning"
SimStateOlderReleaseMsg "error"
InitInArrayFormatMsg "warning"
StrictBusMsg "ErrorLevel1"
BusNameAdapt "WarnAndRepair"
NonBusSignalsTreatedAsBus "none"
SymbolicDimMinMaxWarning "warning"
LossOfSymbolicDimsSimulationWarning "warning"
LossOfSymbolicDimsCodeGenerationWarning "error"
BlockIODiagnostic "none"
SFUnusedDataAndEventsDiag "warning"
SFUnexpectedBacktrackingDiag "warning"
SFInvalidInputDataAccessInChartInitDiag "warning"
SFNoUnconditionalDefaultTransitionDiag "warning"
SFTransitionOutsideNaturalParentDiag "warning"
SFUnreachableExecutionPathDiag "warning"
SFUndirectedBroadcastEventsDiag "warning"
SFTransitionActionBeforeConditionDiag "warning"
SFOutputUsedAsStateInMooreChartDiag "error"
SFTemporalDelaySmallerThanSampleTimeDiag "warning"
SFSelfTransitionDiag "warning"
SFExecutionAtInitializationDiag "none"
SFMachineParentedDataDiag "warning"
IntegerSaturationMsg "warning"
AllowedUnitSystems "all"
UnitsInconsistencyMsg "warning"
AllowAutomaticUnitConversions on
}
Simulink.HardwareCC {
$ObjectID 13
Version "1.16.5"
DisabledProps []
Description ""
ProdBitPerChar 8
ProdBitPerShort 16
ProdBitPerInt 32
ProdBitPerLong 32
ProdBitPerLongLong 64
ProdBitPerFloat 32
ProdBitPerDouble 64
ProdBitPerPointer 32
ProdBitPerSizeT 32
ProdBitPerPtrDiffT 32
ProdLargestAtomicInteger "Char"
ProdLargestAtomicFloat "None"
ProdIntDivRoundTo "Undefined"
ProdEndianess "Unspecified"
ProdWordSize 32
ProdShiftRightIntArith on
ProdLongLongMode off
ProdHWDeviceType "32-bit Generic"
TargetBitPerChar 8
TargetBitPerShort 16
TargetBitPerInt 32
TargetBitPerLong 32
TargetBitPerLongLong 64
TargetBitPerFloat 32
TargetBitPerDouble 64
TargetBitPerPointer 32
TargetBitPerSizeT 32
TargetBitPerPtrDiffT 32
TargetLargestAtomicInteger "Char"
TargetLargestAtomicFloat "None"
TargetShiftRightIntArith on
TargetLongLongMode off
TargetIntDivRoundTo "Undefined"
TargetEndianess "Unspecified"
TargetWordSize 32
TargetPreprocMaxBitsSint 32
TargetPreprocMaxBitsUint 32
TargetHWDeviceType "Specified"
TargetUnknown on
ProdEqTarget on
UseEmbeddedCoderFeatures on
UseSimulinkCoderFeatures on
}
Simulink.ModelReferenceCC {
$ObjectID 14
Version "1.16.5"
DisabledProps []
Description ""
UpdateModelReferenceTargets "IfOutOfDateOrStructuralChange"
EnableRefExpFcnMdlSchedulingChecks on
CheckModelReferenceTargetMessage "error"
EnableParallelModelReferenceBuilds off
ParallelModelReferenceErrorOnInvalidPool on
ParallelModelReferenceMATLABWorkerInit "None"
ModelReferenceNumInstancesAllowed "Multi"
PropagateVarSize "Infer from blocks in model"
ModelDependencies ""
ModelReferencePassRootInputsByReference on
ModelReferenceMinAlgLoopOccurrences off
PropagateSignalLabelsOutOfModel off
SupportModelReferenceSimTargetCustomCode off
}
Simulink.SFSimCC {
$ObjectID 15
Version "1.16.5"
DisabledProps []
Description ""
SimCustomSourceCode ""
SimCustomHeaderCode ""
SimCustomInitializer ""
SimCustomTerminator ""
SimReservedNameArray []
SimUserSources ""
SimUserIncludeDirs ""
SimUserLibraries ""
SimUserDefines ""
SimCustomCompilerFlags ""
SimCustomLinkerFlags ""
SFSimEcho on
SimCtrlC on
SimIntegrity on
SimUseLocalCustomCode off
SimParseCustomCode on
SimBuildMode "sf_incremental_build"
SimGenImportedTypeDefs off
ModelFunctionsGlobalVisibility "on"
CompileTimeRecursionLimit 50
EnableRuntimeRecursion on
}
Simulink.RTWCC {
$BackupClass "Simulink.RTWCC"
$ObjectID 16
Version "1.16.5"
Array {
Type "Cell"
Dimension 13
Cell "IncludeHyperlinkInReport"
Cell "GenerateTraceInfo"
Cell "GenerateTraceReport"
Cell "GenerateTraceReportSl"
Cell "GenerateTraceReportSf"
Cell "GenerateTraceReportEml"
Cell "PortableWordSizes"
Cell "GenerateWebview"
Cell "GenerateCodeMetricsReport"
Cell "GenerateCodeReplacementReport"
Cell "GenerateMissedCodeReplacementReport"
Cell "GenerateErtSFunction"
Cell "CreateSILPILBlock"
PropName "DisabledProps"
}
SystemTargetFile "grt.tlc"
HardwareBoard "None"
TLCOptions ""
GenCodeOnly off
MakeCommand "make_rtw"
GenerateMakefile on
PackageGeneratedCodeAndArtifacts off
PackageName ""
TemplateMakefile "grt_default_tmf"
PostCodeGenCommand ""
Description ""
GenerateReport off
SaveLog off
RTWVerbose on
RetainRTWFile off
RTWBuildHooks []
ProfileTLC off
TLCDebug off
TLCCoverage off
TLCAssert off
RTWUseLocalCustomCode off
RTWUseSimCustomCode off
CustomSourceCode ""
CustomHeaderCode ""
CustomInclude ""
CustomSource ""
CustomLibrary ""
CustomDefine ""
CustomLAPACKCallback ""
CustomInitializer ""
CustomTerminator ""
Toolchain "Automatically locate an installed toolchain"
BuildConfiguration "Faster Builds"
CustomToolchainOptions []
IncludeHyperlinkInReport off
LaunchReport off
PortableWordSizes off
CreateSILPILBlock "None"
CodeExecutionProfiling off
CodeExecutionProfileVariable "executionProfile"
CodeProfilingSaveOptions "SummaryOnly"
CodeProfilingInstrumentation off
SILDebugging off
TargetLang "C"
IncludeBusHierarchyInRTWFileBlockHierarchyMap off
GenerateTraceInfo off
GenerateTraceReport off
GenerateTraceReportSl off
GenerateTraceReportSf off
GenerateTraceReportEml off
GenerateWebview off
GenerateCodeMetricsReport off
GenerateCodeReplacementReport off
GenerateMissedCodeReplacementReport off
RTWCompilerOptimization "off"
ObjectivePriorities []
RTWCustomCompilerOptimizations ""
CheckMdlBeforeBuild "Off"
SharedConstantsCachingThreshold 1024
Array {
Type "Handle"
Dimension 2
Simulink.CodeAppCC {
$ObjectID 17
Version "1.16.5"
Array {
Type "Cell"
Dimension 25
Cell "IgnoreCustomStorageClasses"
Cell "InsertBlockDesc"
Cell "SFDataObjDesc"
Cell "SimulinkDataObjDesc"
Cell "DefineNamingRule"
Cell "SignalNamingRule"
Cell "ParamNamingRule"
Cell "InlinedPrmAccess"
Cell "CustomSymbolStr"
Cell "CustomSymbolStrGlobalVar"
Cell "CustomSymbolStrType"
Cell "CustomSymbolStrField"
Cell "CustomSymbolStrFcn"
Cell "CustomSymbolStrBlkIO"
Cell "CustomSymbolStrTmpVar"
Cell "CustomSymbolStrMacro"
Cell "IgnoreTestpoints"
Cell "InsertPolySpaceComments"
Cell "MATLABFcnDesc"
Cell "InternalIdentifier"
Cell "CustomSymbolStrModelFcn"
Cell "CustomSymbolStrFcnArg"
Cell "CustomSymbolStrUtil"
Cell "CustomUserTokenString"
Cell "ReqsInCode"
PropName "DisabledProps"
}
Description ""
Comment ""
ForceParamTrailComments off
GenerateComments on
CommentStyle "Auto"
IgnoreCustomStorageClasses on
IgnoreTestpoints off
IncHierarchyInIds off
MaxIdLength 31
PreserveName off
PreserveNameWithParent off
ShowEliminatedStatement off
OperatorAnnotations off
IncAutoGenComments off
SimulinkDataObjDesc off
SFDataObjDesc off
MATLABFcnDesc off
IncDataTypeInIds off
MangleLength 1
CustomSymbolStrGlobalVar "$R$N$M"
CustomSymbolStrType "$N$R$M_T"
CustomSymbolStrField "$N$M"
CustomSymbolStrFcn "$R$N$M$F"
CustomSymbolStrModelFcn "$R$N"
CustomSymbolStrFcnArg "rt$I$N$M"
CustomSymbolStrBlkIO "rtb_$N$M"
CustomSymbolStrTmpVar "$N$M"
CustomSymbolStrMacro "$R$N$M"
CustomSymbolStrUtil "$N$C"
CustomUserTokenString ""
CustomCommentsFcn ""
DefineNamingRule "None"
DefineNamingFcn ""
ParamNamingRule "None"
ParamNamingFcn ""
SignalNamingRule "None"
SignalNamingFcn ""
InsertBlockDesc off
InsertPolySpaceComments off
SimulinkBlockComments on
MATLABSourceComments off
EnableCustomComments off
InternalIdentifierFile ""
InternalIdentifier "Shortened"
InlinedPrmAccess "Literals"
ReqsInCode off
UseSimReservedNames off
ReservedNameArray []
}
Simulink.GRTTargetCC {
$BackupClass "Simulink.TargetCC"
$ObjectID 18
Version "1.16.5"
Array {
Type "Cell"
Dimension 16
Cell "IncludeMdlTerminateFcn"
Cell "RemoveResetFunc"
Cell "SuppressErrorStatus"
Cell "ERTCustomFileBanners"
Cell "GenerateSampleERTMain"
Cell "GenerateTestInterfaces"
Cell "ModelStepFunctionPrototypeControlCompliant"
Cell "PortableWordSizes"
Cell "PurelyIntegerCode"
Cell "GenerateAllocFcn"
Cell "SupportComplex"
Cell "SupportAbsoluteTime"
Cell "SupportContinuousTime"
Cell "SupportNonInlinedSFcns"
Cell "ExistingSharedCode"
Cell "RemoveDisableFunc"
PropName "DisabledProps"
}
Description ""
TargetFcnLib "ansi_tfl_tmw.mat"
TargetLibSuffix ""
TargetPreCompLibLocation ""
GenFloatMathFcnCalls "NOT IN USE"
TargetLangStandard "C89/C90 (ANSI)"
CodeReplacementLibrary "None"
UtilityFuncGeneration "Auto"
ERTMultiwordTypeDef "System defined"
ERTMultiwordLength 256
MultiwordLength 2048
GenerateFullHeader on
InferredTypesCompatibility off
ExistingSharedCode ""
GenerateSampleERTMain off
GenerateTestInterfaces off
ModelReferenceCompliant on
ParMdlRefBuildCompliant on
CompOptLevelCompliant on
ConcurrentExecutionCompliant on
IncludeMdlTerminateFcn on
GeneratePreprocessorConditionals "Disable all"
CombineOutputUpdateFcns off
CombineSignalStateStructs off
SuppressErrorStatus off
ERTFirstTimeCompliant off
IncludeFileDelimiter "Auto"
ERTCustomFileBanners off
SupportAbsoluteTime on
LogVarNameModifier "rt_"
MatFileLogging on
MultiInstanceERTCode off
CodeInterfacePackaging "Nonreusable function"
SupportNonFinite on
SupportComplex on
PurelyIntegerCode off
SupportContinuousTime on
SupportNonInlinedSFcns on
RemoveDisableFunc off
RemoveResetFunc off
SupportVariableSizeSignals off
ParenthesesLevel "Nominal"
CastingMode "Nominal"
MATLABClassNameForMDSCustomization "Simulink.SoftwareTarget.GRTCustomization"
ModelStepFunctionPrototypeControlCompliant off
CPPClassGenCompliant on
AutosarCompliant off
MDXCompliant off
GRTInterface on
GenerateAllocFcn off
UseToolchainInfoCompliant on
GenerateSharedConstants on
CoderGroups []
UseMalloc off
ExtMode off
ExtModeStaticAlloc off
ExtModeTesting off
ExtModeStaticAllocSize 1000000
ExtModeTransport 0
ExtModeMexFile "ext_comm"
ExtModeMexArgs ""
ExtModeIntrfLevel "Level1"
RTWCAPISignals off
RTWCAPIParams off
RTWCAPIStates off
RTWCAPIRootIO off
GenerateASAP2 off
MultiInstanceErrorCode "Error"
}
PropName "Components"
}
}
SlCovCC.ConfigComp {
$ObjectID 19
Version "1.16.5"
DisabledProps []
Description "Simulink Coverage Configuration Component"
Name "Simulink Coverage"
CovEnable off
CovScope "EntireSystem"
CovIncludeTopModel on
RecordCoverage off
CovPath "/"
CovSaveName "covdata"
CovCompData ""
CovMetricSettings "dw"
CovFilter ""
CovHTMLOptions ""
CovNameIncrementing off
CovHtmlReporting on
CovForceBlockReductionOff on
CovEnableCumulative on
CovSaveCumulativeToWorkspaceVar on
CovSaveSingleToWorkspaceVar on
CovCumulativeVarName "covCumulativeData"
CovCumulativeReport off
CovSaveOutputData on
CovOutputDir "slcov_output/$ModelName$"
CovDataFileName "$ModelName$_cvdata"
CovShowResultsExplorer on
CovReportOnPause on
CovModelRefEnable "off"
CovModelRefExcluded ""
CovExternalEMLEnable off
CovSFcnEnable on
CovBoundaryAbsTol 1e-05
CovBoundaryRelTol 0.01
CovUseTimeInterval off
CovStartTime 0
CovStopTime 0
}
PropName "Components"
}
Name "Configuration"
ExtraOptions ""
CurrentDlgPage "Solver"
ConfigPrmDlgPosition [ 430, 225, 1490, 855 ]
}
PropName "ConfigurationSets"
}
Simulink.ConfigSet {
$PropName "ActiveConfigurationSet"
$ObjectID 8
}
Object {
$PropName "DataTransfer"
$ObjectID 20
$ClassName "Simulink.GlobalDataTransfer"
DefaultTransitionBetweenSyncTasks "Ensure deterministic transfer (maximum delay)"
DefaultTransitionBetweenAsyncTasks "Ensure data integrity only"
DefaultTransitionBetweenContTasks "Ensure deterministic transfer (minimum delay)"
DefaultExtrapolationMethodBetweenContTasks "None"
AutoInsertRateTranBlk [0]
}
ExplicitPartitioning off
BlockDefaults {
ForegroundColor "black"
BackgroundColor "white"
DropShadow off
NamePlacement "normal"
FontName "Helvetica"
FontSize 10
FontWeight "normal"
FontAngle "normal"
ShowName on
BlockRotation 0
BlockMirror off
}
AnnotationDefaults {
HorizontalAlignment "center"
VerticalAlignment "middle"
ForegroundColor "black"
BackgroundColor "white"
DropShadow off
FontName "Helvetica"
FontSize 10
FontWeight "normal"
FontAngle "normal"
UseDisplayTextAsClickCallback off
}
LineDefaults {
FontName "Helvetica"
FontSize 9
FontWeight "normal"
FontAngle "normal"
}
MaskDefaults {
SelfModifiable "off"
IconFrame "on"
IconOpaque "opaque"
RunInitForIconRedraw "off"
IconRotate "none"
PortRotate "default"
IconUnits "autoscale"
}
MaskParameterDefaults {
Evaluate "on"
Tunable "on"
NeverSave "off"
Internal "off"
ReadOnly "off"
Enabled "on"
Visible "on"
ToolTip "on"
}
BlockParameterDefaults {
Block {
BlockType Clock
DisplayTime off
Decimation "10"
}
Block {
BlockType S-Function
FunctionName "system"
SFunctionModules "''"
PortCounts "[]"
}
Block {
BlockType Sin
SineType "Time based"
TimeSource "Use simulation time"
Amplitude "1"
Bias "0"
Frequency "1"
Phase "0"
Samples "10"
Offset "0"
SampleTime "-1"
VectorParams1D on
}
Block {
BlockType ToWorkspace
VariableName "simulink_output"
MaxDataPoints "1000"
Decimation "1"
SaveFormat "Array"
Save2DSignal "Inherit from input (this choice will be removed - see release notes)"
FixptAsFi off
NumInputs "1"
SampleTime "0"
}
}
System {
Name "rbfsim"
Location [12, 45, 1958, 1234]
Open on
ModelBrowserVisibility off
ModelBrowserWidth 200
ScreenColor "white"
PaperOrientation "landscape"
PaperPositionMode "auto"
PaperType "usletter"
PaperUnits "inches"
TiledPaperMargins [0.196850, 0.196850, 0.196850, 0.196850]
TiledPageScale 1
ShowPageBoundaries off
ZoomFactor "378"
ReportName "simulink-default.rpt"
SIDHighWatermark "6"
Block {
BlockType Clock
Name "Clock"
SID "1"
Position [75, 137, 115, 163]
ZOrder -1
DisplayTime on
}
Block {
BlockType ToWorkspace
Name "Position1"
SID "2"
Ports [1]
Position [330, 35, 390, 65]
ZOrder -2
VariableName "y"
MaxDataPoints "inf"
SampleTime "-1"
}
Block {
BlockType S-Function
Name "S-Function"
SID "3"
Ports [1, 1]
Position [185, 31, 255, 69]
ZOrder -3
FunctionName "rbf"
SFunctionDeploymentMode off
EnableBusSupport off
SFcnIsStateOwnerBlock off
}
Block {
BlockType Sin
Name "Sine Wave"
SID "4"
Ports [0, 1]
Position [80, 35, 110, 65]
ZOrder -4
SampleTime "0"
}
Block {
BlockType ToWorkspace
Name "To Workspace"
SID "5"
Ports [1]
Position [165, 136, 210, 164]
ZOrder -5
VariableName "t"
MaxDataPoints "inf"
SampleTime "-1"
}
Line {
ZOrder 1
SrcBlock "S-Function"
SrcPort 1
DstBlock "Position1"
DstPort 1
}
Line {
ZOrder 2
SrcBlock "Clock"
SrcPort 1
DstBlock "To Workspace"
DstPort 1
}
Line {
ZOrder 3
SrcBlock "Sine Wave"
SrcPort 1
DstBlock "S-Function"
DstPort 1
}
}
}
RBF函数:
function[sys,x0,str,ts]=spacemodel(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u)
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag=',num2str(flag)]);
end
function[sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 7;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0=[];
str =[];
ts =[];
function sys = mdlOutputs(t,x,u)
x=u(1);
c=[-0.5 -0.25 0 0.25 0.5];
b=[0.2 0.2 0.2 0.2 0.2]';
W=ones(5,1)
h=zeros(5,1)
for j=1:1:5
h(j)=exp(-norm(x-c(:,j))^2/(2*b(j)*b(j)));
end
y=W'*h;
sys(1)=y;
sys(2)=x;
sys(3)=h(1);
sys(4)=h(2);
sys(5)=h(3);
sys(6)=h(4);
sys(7)=h(5);
结果可视化:
close all
figure(1);
plot(t,y(:,1),'k','linewidth',2);
xlabel('time(s)');ylabel('y');
figure(2);
plot(y(:,2),y(:,3),'r','linewidth',2)
xlabel('x');ylabel('hj');
hold on;
plot(y(:,2),y(:,4),'k','linewidth',2);
hold on
plot(y(:,2),y(:,5),'g','linewidth',2);
hold on
plot(y(:,2),y(:,6),'b','linewidth',2);
hold on
plot(y(:,2),y(:,7),'y','linewidth',2);