필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Trying to convert this C++ Code to work in MatLab

조회 수: 1 (최근 30일)
random1072
random1072 2020년 7월 21일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello, I am currently trying to get this c++ code to work in Matlab so I can understand the differences between the two programming systems. Can someone please show me what the code for the following C++ code would be in Matlab. I upladed a picture as well as simply copied in the text so you can easily copy it as well as uploaded picture from problem. Thank you
Computer program: (C language)
#include<stdio.h>
#include<conio.h>
double lx=10.0;
int n=20;
main()
{
int i;
double h,Ta,dx=0;
double To[100]={0},T[100]={0},error=100;
dx=lx/n;
h=0.02;
Ta=20;
while(error>1.0e-10)
{
for(i=1;i<=n;i++)
{
To[i]=T[i];
}
T[0]=40.0; To[0]=40.0;
T[n]=200.0; To[n]=200.0;
for(i=1;i<=n-1;i++)
{
T[i]=(To[i+1]+To[i-1]+h*dx*dx*Ta)/(2+h*dx*dx);
}
float e=0,eold=0;
for(i=1;i<=n-1;i++)
{
e=T[i]-To[i];
if(e>eold)
{
eold=e;
error=e;
}
}
}
printf("\n\nFINAL RESULT\n\n");
for(i=0;i<=n;i++)
{
printf("%f\t",T[i]);
}
}
​​​​​​​Temperature at the internal nodes:
The temperature convergence is set to 10-10 for all the cases.
  댓글 수: 1
Steven Lord
Steven Lord 2020년 7월 21일
This sounds like a homework assignment. If it is, please show us the MATLAB code you've written so far and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.

답변 (0개)

이 질문은 마감되었습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by