{"id":161,"date":"2011-11-08T05:02:22","date_gmt":"2011-11-08T05:02:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2011\/11\/08\/auto-solver-settings\/"},"modified":"2011-11-08T05:02:22","modified_gmt":"2011-11-08T05:02:22","slug":"auto-solver-settings","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2011\/11\/08\/auto-solver-settings\/","title":{"rendered":"Auto Solver Settings"},"content":{"rendered":"<p>When looking at the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/simulink\/gui\/bq7cmsp-1.html\">solver configuration<\/a> of a new model, you probably noticed that many settings are set to <em>Auto<\/em>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q3\/solverAutoSettings.png\" alt=\"Simulink solver configuration\"><\/p>\r\n\r\n<p>When an <em>Auto<\/em> option is provided for a setting, it is because we feel that this <em>Auto<\/em> setting will be appropriate for most users.<\/p>\r\n\r\n<p>Today I want to show an example illustrating that this is not always the case.<\/p>\r\n\r\n<p><strong>The Question<\/strong><\/p>\r\n\r\n<p>Last week a user asked me the following question:<\/p>\r\n\r\n<p><em>Why is my model running significantly slower when I set the stop time to infinite, versus a large number like 500,000 seconds?<\/em><\/p>\r\n\r\n<p><strong>The Investigation<\/strong><\/p>\r\n\r\n<p>To begin, here is an image of what the model looks like:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q3\/satelliteModel.png\" alt=\"Simulink solver configuration\"><\/p>\r\n\r\n<P>We can see that this is a <a href=\"https:\/\/www.mathworks.com\/products\/simmechanics\/\">SimMechanics<\/a> model simulating the motion of a satellite rotating around the Earth. Obviously, this kind of system has a very slow dynamics and can probably take very large time steps without loosing accuracy significantly.<\/p>\r\n\r\n<p>One thing I like to do when a user reports a model being slow is to log the time vector of the simulation<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q3\/log_time.png\" alt=\"Simulink solver configuration\"><\/p>\r\n\r\n<p>and display it using a line like:<\/p>\r\n\r\n<code>semilogy(tout(1:end-1),diff(tout))<\/code>\r\n\r\n<p>The log axis allows to differentiate large versus small time steps and to identify some common patterns.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q3\/semilogy.png\" alt=\"Comparing time steps\"><\/p>\r\n\r\n<p>In this case, it clearly showed that with a stop time of 500,000 sec, the steps taken could go up to 1000sec, but with the stop time set to infinity, the time steps taken are never higher than 0.2sec.\r\n\r\n<p><strong>The explanation<\/strong><\/p>\r\n\r\n<p>Let's right click on this setting to reach its documentation:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q3\/maxStepSizeWhatsThis.png\" alt=\"Reaching the documentation for the Max Step Size setting\"><\/p>\r\n\r\n<p>The first thing we see, highlighted by a red rectangle here, is the equation linking stop time and max step size. Many users are familiar with this equation. But when reading the text, we find the description of the behavior when the stop time is infinite.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q3\/maxStepSizeDoc.png\" alt=\"Documentation for the Max Step Size setting\"><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Are the <em>Auto<\/em> and default settings in Simulink appropriate for you? Please share your experience by leaving a  <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=161&amp;#comment\">comment here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>When looking at the solver configuration of a new model, you probably noticed that many settings are set to Auto.\r\n\r\n\r\n\r\nWhen an Auto option is provided for a setting, it is because we feel that this... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2011\/11\/08\/auto-solver-settings\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,33],"tags":[233,232],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/161"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=161"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/161\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}