Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Help with a two variables equation?

1 visualizzazione (ultimi 30 giorni)
Nir
Nir il 21 Dic 2014
Chiuso: MATLAB Answer Bot il 20 Ago 2021
Hi there, Im trying to create a 3D graph of the Constant Surface Heat flux in a material. The equation is in the pic i added. The thing is, i get problems with multiplying the matrices (x and t).. What am i doing wrong? is there any one who can help write this code? Thank you! (the only variables are x and t, all others are constant.)
  2 Commenti
Star Strider
Star Strider il 21 Dic 2014
Posting your code would help significantly.
We’re good, but we can’t guess what code you’ve written.
Nir
Nir il 21 Dic 2014
This is my code and what i get is in the picture
clc; clear variables; close all;
x=0:0.01:10;
t=0:0.01:10;
alpha=11.23*10^-5;
Ti=20;
k=368;
q=0.5*10^6;
T(x,t)=((2*q)/(k))*sqrt((alpha*t)/pi).*exp((-(x.^2))/4*alpha*t')-((q*x)/(k)).*(1-erf(x/(sqrt(2*alpha*t))))-Ti;

Risposte (1)

Roger Stafford
Roger Stafford il 22 Dic 2014
In the line
T(x,t)=((2*q)/(k))*......
if T is to be a matrix of values, then the 'x' and 't' values must be indices which are positive integers, and that is not the case with your code. For generating a surface in 3D you should use 'meshgrid' or 'ndgrid' to create a grid of value pairs and then call on 'surf'.
[x,t] = meshgrid(0:0.01:10,0:0.01:10);
T = ((2*q)/(k))*......
surf(x,y,T)
Also I notice several discrepancies between the image of "T(x,t) = ..." equation and the equation you have coded:
1) The -Ti on the left should become +Ti on the right.
2) exp((-(x.^2))/4*alpha*t') should be exp(-x.^2./(4*alpha*t)).
3) x/(sqrt(2*alpha*t)) should be x./(2*sqrt(alpha*t)).
Also it was not necessary to convert the erfc to 1-erf, since matlab already has an erfc function.
  2 Commenti
Nir
Nir il 22 Dic 2014
I tried that but still the code just wont work.. this is my code now:
clc;
clear variables;
close all;
x=0:0.01:10; t=0:0.01:10; alpha=11.23*10^-5; Ti=20; k=368; q=0.5*10^6;
T(x,t)=((2*q)/(k))*sqrt((alpha*t)/pi).*exp(-x.^2/4*alpha*t)-((q*x)/(k)).*(erfc(x./(2*sqrt(alpha*t))))+Ti;
Thank you so much for the help!
Roger Stafford
Roger Stafford il 22 Dic 2014
Modificato: Roger Stafford il 22 Dic 2014
You didn't take my and Mohammad Abouali's advice on 2):
2) exp((-(x.^2))/4*alpha*t') should be exp(-x.^2./(4*alpha*t)).
Without that added 'dot' it would give you the error message. Also you are multiplying by alpha*t here and the operation shown in your original image requires that you divide by these quantities.

Community Treasure Hunt

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

Start Hunting!

Translated by