{"id":19130295,"url":"https://github.com/mathworks/simple-heat-equation-solver","last_synced_at":"2025-05-06T00:56:13.317Z","repository":{"id":92436542,"uuid":"226262002","full_name":"mathworks/Simple-Heat-Equation-solver","owner":"mathworks","description":"Simple Heat Equation solver using finite difference method","archived":false,"fork":false,"pushed_at":"2023-03-18T06:02:41.000Z","size":5704,"stargazers_count":20,"open_issues_count":0,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-06T00:56:07.069Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-12-06T06:32:11.000Z","updated_at":"2025-02-06T08:38:36.000Z","dependencies_parsed_at":"2025-04-19T06:38:44.613Z","dependency_job_id":"2f91cfeb-7f2f-4935-81c2-4da40f5e82ec","html_url":"https://github.com/mathworks/Simple-Heat-Equation-solver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks%2FSimple-Heat-Equation-solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks%2FSimple-Heat-Equation-solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks%2FSimple-Heat-Equation-solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks%2FSimple-Heat-Equation-solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathworks","download_url":"https://codeload.github.com/mathworks/Simple-Heat-Equation-solver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252601692,"owners_count":21774660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T06:10:12.642Z","updated_at":"2025-05-06T00:56:13.307Z","avatar_url":"https://github.com/mathworks.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Finite differences for the 2D heat equation\n[![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=mathworks/Simple-Heat-Equation-solver)\n[![View Simple Heat Equation solver on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://jp.mathworks.com/matlabcentral/fileexchange/59916-simple-heat-equation-solver)\n\nImplementation of a simple numerical schemes for the heat equation.\n\n\n\n\u003cimg src=\"https://latex.codecogs.com/gif.latex?\\frac{\\partial\u0026space;u}{\\partial\u0026space;t}=\\alpha\u0026space;\\left(\\frac{\\partial^2\u0026space;u}{\\partial\u0026space;x^2\u0026space;}+\\frac{\\partial^2\u0026space;u}{\\partial\u0026space;y^2\u0026space;}\\right).\"/\u003e\n\n\n\nApplying the second-order centered differences to approximate the spatial derivatives,\n\n\n\n\u003cimg src=\"https://latex.codecogs.com/gif.latex?\\frac{\\partial\u0026space;u}{\\partial\u0026space;t}=\\alpha\u0026space;\\left(\\frac{u(i-1,j)-2u(i,j)+u(i+1,j)}{\\Delta\u0026space;x^2\u0026space;}+\\frac{u(i,j-1)-2u(i,j)+u(i,j+1)}{\\Delta\u0026space;y^2\u0026space;}\\right).\"/\u003e\n\n\n\nNeumann boundary condition is employed for no-heat flux, thus please note that the grid location is staggered. Once the right hand side is obtained, the equation can be solved by the ODE suite. Here we use ode15s. Copyright 2015-2016 The MathWorks, Inc.\n\n\n\n\n![image_0.png](SimpleHeatEquation_images/image_0.png)\n\n\n# Problem Setup\n```matlab\nN = 50; % Number of grid in x,y-direction\nL = 4*pi; % Domain size\n\n% Grid point\nx = linspace(0,L,N);\ny = linspace(0,L,N);\n% Make it staggered.\nx = (x(1:end-1)+x(2:end))/2;\ny = (y(1:end-1)+y(2:end))/2;\n[X,Y] = meshgrid(x,y);\n```\n# Initial Condition\n```matlab\n% Let's use MATLAB logo.\n% A variable u0 is defined at the center of each grid cell\n% thus the number of grid point is N-1.\nu0(:,:) = peaks(N-1);\n\n% Plot it\nhandle_surf = surf(X,Y,u0);\nhandle_axes = gca;\nhandle_axes.ZLim = [-10,10];\nhandle_axes.CLim = [-10,10];\ntitle('Evolution of MATLAB Logo by Heat equation');\n```\n\n![figure_0.png](SimpleHeatEquation_images/figure_0.png)\n\n```matlab\n```\n# Simulation\n```matlab\ndx = x(2)-x(1); % spatial grid size\nalpha = 2; % coefficient\ntspan = linspace(0,1,40);\n[t,u] = ode15s(@(t,x)getRHS(x,alpha,dx,N),tspan,u0(:));\n```\n# Visualize\n```matlab\nTn = length(t);\nu = reshape(u,Tn,N-1,N-1);\n\nfilename = 'heat.gif';\nfor ii=1:Tn\n    Z = u(ii,:,:);\n    Z = squeeze(Z);\n    handle_surf.ZData = Z;\n    drawnow;\n    frame = getframe(gcf);\n    im = frame2im(frame);\n    [A,map] = rgb2ind(im,256);\n    if ii==1\n        imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',0.05);\n    else\n        imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',0.05);\n    end\nend\n```\n\n![figure_1.png](SimpleHeatEquation_images/figure_1.png)\n\nCopyright 2015-2016 The MathWorks, Inc.\n[![View Simple Heat Equation solver on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://jp.mathworks.com/matlabcentral/fileexchange/59916-simple-heat-equation-solver)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathworks%2Fsimple-heat-equation-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathworks%2Fsimple-heat-equation-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathworks%2Fsimple-heat-equation-solver/lists"}