Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

3 ビュー (過去 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